Saving and loading a Multi-dimensional array

Non-platform specific questions.

Saving and loading a Multi-dimensional array

Postby Hblade » Fri Jan 27, 2012 9:50 pm

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 :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby SuperSonic » Sat Jan 28, 2012 12:30 am

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^^
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby Hblade » Sat Jan 28, 2012 2:43 am

I understand ^^ Gag explained to me in a PM.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby Leif » Sat Jan 28, 2012 7:30 am

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
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby Hblade » Sat Jan 28, 2012 8:18 pm

Wow thats genius :) thanks
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby Game A Gogo » Sat Jan 28, 2012 8:41 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby Hblade » Sat Jan 28, 2012 9:20 pm

true :3
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Saving and loading a Multi-dimensional array

Postby DeltaLeeds » Mon Jul 04, 2016 4:16 pm

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.
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron