Files/SaveState/LoadState

Monkey Forums/Monkey Programming/Files/SaveState/LoadState

GfK(Posted 2011) [#1]
Just looking at some file handling code in Blitzmax... I don't know how to convert it to Monkey.

I basically need to have a couple of different files; a preferences file, a player index file, and a bunch of player saved games, but it seems like Monkey Apps can have only one file for saved data? Is that correct? Is this typical of all Android/iOS apps?

SaveState and LoadState seems to be a really crude way of doing it. Plus there seems to be a 1MB limit on the total filesize which really isn't good. Is that limitation the same on all targets or just HTML5?


Chaduke(Posted 2011) [#2]
You can have as many files as you want, they all need to be placed in a folder that ends in .data

If you have a project called MyGame, then make a folder at the root called MyGame.data and put all your files in there. When you call a function that accesses a file, just use the filename.

Someone else will have to answer about the file size limit, personally I've never had an issue with that, and I've built programs on pretty much everything but Android.


GfK(Posted 2011) [#3]
You can have as many files as you want, they all need to be placed in a folder that ends in .data
...but SaveState() doesn't have a filename field...


Raz(Posted 2011) [#4]
You're going to have to come up with a system for storing all of this information in a single file. Else, depending on the target (e.g. GLFW) you can use the OS module which and save and write files.

It is crude, but I think it's to guarantee support for each platform.


GfK(Posted 2011) [#5]
Yeah I think I'll rustle up a file i/o module that works much the same as Blitzmax did, but stores everything in a string ready for SaveState.

Two possible problems though; maximum filesize, and write speed (you have to save ALL user profiles/data every time). Seems to be horribly slow in the iPhone emulator. Hope its faster on the real thing.


Raz(Posted 2011) [#6]
check the skn3 config demo example in the bananas directory.

Personally, I just had a static AppState class that would read/write/create the settings and what not.


Chaduke(Posted 2011) [#7]
Wow, I didn't realize writing to external files was that limited. I should have checked it out before I posted. I've been jumping around too many different development platforms lately.


therevills(Posted 2011) [#8]
Seems to be horribly slow in the iPhone emulator


I found the simulator faster than my iPod... but that was in the rendering, reading/writing was fine... How are you currently doing it?


GfK(Posted 2011) [#9]
How are you currently doing it?
I'm not, yet!

My plan when I get around to it, is to come up with a kind of 'filesystem' class, that I can add/delete/modify files in, then just use SaveState to save the whole lot. Its not ideal having to save everything, every time, but I don't see any other way.


therevills(Posted 2011) [#10]
Sorry I was asking about how you are doing it in iOS which is "horribly slow"?


GfK(Posted 2011) [#11]
Sorry I was asking about how you are doing it in iOS which is "horribly slow"?
Oh!

It was really just some stress tests to see how much data could be stored with SaveState and LoadState. With a million bytes (admittedly a lot) it took about 25s before the app just died in the iOS emulator (it worked fine, and really fast in HTML5). Realistically, a saved game is about 1,000 bytes, and I'll never be storing more than 16 of them (one per player), plus a couple other small files... I might not be saving more than about 20k so its possibly not the huge problem I've initially seen it as.

Thinking about it, I wonder if throwing a huge amount of data at it made it hang pretty quickly, and it was iOS that terminated the app after a timout because it locked up. I don't know enough about it to be certain.