Page 1 of 1

Saving and loading a Multi-dimensional array

PostPosted: Fri Jan 27, 2012 9:50 pm
by Hblade
How would I go about saving arrays that have multiple dimensions?
Code: Select all
arra[type][number[value]


I'm planning on having a weapon system that has stats based off this. For example:
Code: Select all
int ITEM_ARRAY[type][ID_number][Cost][stat1][stat2][stat3][stat4][stat5][stat6][stat7][stat8][stat9]


If there is a better way of doing this I'd love to know it :)

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 12:30 am
by SuperSonic
Shouldn't you just do: int array[256][256][10]

So if you wanted to access the cost of weapon no. 42, you would just do: array[whatever number weapons are][42][0]

Not sure if that's what you meant^^

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 2:43 am
by Hblade
I understand ^^ Gag explained to me in a PM.

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 7:30 am
by Leif
If I'm right, question is "how to save multi-dimentional array using savevars function ?". If it's so, then:
You know, that GE supports only saving/loading one-dimentional arrays created in special dialog window with setting "Save group"

My way is:

1. For example you have 10 types of weapon (counted from 0 to 9). Each weapon have 12 parameters:[type][ID_number][Cost][stat1]...[stat9].
So, we create an array with dimention 10x12, save group "weapons".
weapon_system_array.png


Now we can save/load it.

2. While using such an array it's convenient to get access this way:

Code: Select all
ITEM_ARRAY[Type*12]       =... ;  // weapon type
ITEM_ARRAY[Type*12+1]   =... ;  // ID_number
ITEM_ARRAY[Type*12+2]   =... ;  // Cost
ITEM_ARRAY[Type*12+3]   =... ;  // stat1
...
ITEM_ARRAY[Type*12+11]  =... ;  // stat9




Described method is best that i found. I use it to work with galaxy map of 40 stars with 25 parameters each.
Hope it helps

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 8:18 pm
by Hblade
Wow thats genius :) thanks

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 8:41 pm
by Game A Gogo
or you could use the file writting functions and use loops to save multi dimensional arrays. Though usually this limits each numbers to 0-255 unless you use tricks to save more than one byte

Re: Saving and loading a Multi-dimensional array

PostPosted: Sat Jan 28, 2012 9:20 pm
by Hblade
true :3

Re: Saving and loading a Multi-dimensional array

PostPosted: Mon Jul 04, 2016 4:16 pm
by DeltaLeeds
Leif wrote:If I'm right, question is "how to save multi-dimentional array using savevars function ?". If it's so, then:
You know, that GE supports only saving/loading one-dimentional arrays created in special dialog window with setting "Save group"

My way is:

1. For example you have 10 types of weapon (counted from 0 to 9). Each weapon have 12 parameters:[type][ID_number][Cost][stat1]...[stat9].
So, we create an array with dimention 10x12, save group "weapons".
weapon_system_array.png


Now we can save/load it.

2. While using such an array it's convenient to get access this way:

Code: Select all
ITEM_ARRAY[Type*12]       =... ;  // weapon type
ITEM_ARRAY[Type*12+1]   =... ;  // ID_number
ITEM_ARRAY[Type*12+2]   =... ;  // Cost
ITEM_ARRAY[Type*12+3]   =... ;  // stat1
...
ITEM_ARRAY[Type*12+11]  =... ;  // stat9




Described method is best that i found. I use it to work with galaxy map of 40 stars with 25 parameters each.
Hope it helps


Is this also the easiest way to save variables for 2 dimensional string? I find it pretty tricky to do so there. Like for instance I'm making a leaderboard thing with names in it right now without struct since I'm not sure how to save struct in gE.