For the project I'm working on, I have some data that I need to store in arrays. I also need to save and load it to/from an external file, but the Array object can only save one array. If I put all my data in a single array it's going to get really messy and I'll probably waste a lot of memory, because some of the data needs an X value in the thousands to work, while others don't need that much at all. Is it possible to save more than one array to the same file? If not, what solution to this problem would you suggest?
I know that I can have more than one array in the game by creating another Array object. The problem arises when I want to save all the arrays to an external file. As far as I know, this is impossible.
And yeah, I could use a 3D array, but as I said it's an inefficient use of memory. A 5000x100x10 array for example needs 18 megabytes. If I divide it into one 5000x20 array, two 1000x100 array, etc, the required disk space would dive to a fraction of that. Also it's a lot easier for me to work with it when each array only has the relevant data in it, like, one array called "combattext" and another called "plotscript" and so on.
have you considered using dynamic arrays, like the built in MMF ones? They will not define items in your array until you call them. So even if you create a 10000x10000x10000 3d array, it will only be as large as the elements you load into it. This is because they are stored as simple linked lists.
If your feeling lazy, you can just use ini files using seperate groups. But that would only be practical if the data your handling isn't that complicated.
Originally Posted by Adam McMillan If your feeling lazy, you can just use ini files using seperate groups. But that would only be practical if the data your handling isn't that complicated.
I don't know if this is the case or not, but if he's working with a level editor, then an INI might actually be slightly more inefficient based on how well you use it.
And again, the idea of a 3D array is great if he's using a level editor, all the way up until you consider that maybe the varying degree's of the array might actually be holding values for objects within the array. So like Object X = X, Y = Y, Z = Type.
You could always use string parser to save more information into one position in an array.
Originally Posted by Adam Phant Try using a second Array object.
I wouldn't. I once had a game that used 2 array objects and MMF would swap values between the arrays at random in a glitchy, bone-crushing, heart-breaking kind of way. Do what Andy says, and have your game use one array and when it comes time to save and load use different filenames to do it.
Edited by the Author.
--
"Del Duio has received 0 trophies. Click here to see them all."
"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"
DXF Games, coming next: Hasslevania 2- This Space for Rent!
Originally Posted by Pixelthief have you considered using dynamic arrays, like the built in MMF ones? They will not define items in your array until you call them. So even if you create a 10000x10000x10000 3d array, it will only be as large as the elements you load into it. This is because they are stored as simple linked lists.
This sounds very nice. I have no idea how a dynamic array works though. Is it the same thing as the Array object but with a bunch of extra functions and the efficient storage method you mentioned? Can I just replace all my old Array events with their dynamic array equivalents, and save disk space?