LoadString vs State

Monkey Forums/Monkey Programming/LoadString vs State

Paul - Taiphoz(Posted 2012) [#1]
Quick question which I think I know the answer to but gona ask anyway.

Currently working on my game, and have a few txt files, one stores the games options coma delimited, another stores level data, another ship flight paths, and another stores scores.

At the moment I am using loadstring , and parsing the data from each to populate the games levels, options, etc.

Will I need to convert all of this to load and save state if I want to put this on say a mobile like ipone or ipad, or xna..

And If I am going to have to dump all of that information into a single state string, any advice ?


therevills(Posted 2012) [#2]
I guess you are currently using the os module SaveString?

You will only need to convert in-game save data, such as your scores, to use SaveState... plus the player's current level etc. You can still use LoadString for the levels etc.

Dave (Gfk) did an excellent "fake" file system module for Load/SaveState which is included in Diddy:

http://code.google.com/p/diddy/source/browse/trunk/examples/FileSystem/testFileSystem.monkey

Oh and beware of the limit with SaveState, I "think" its around 1MB but it does change per target, if I rememeber rightly...


Paul - Taiphoz(Posted 2012) [#3]
So all my levels can remain in their own text files, and I can keep using LoadString to pull them in, even on iPhone for example or XNA ?


ziggy(Posted 2012) [#4]
So all my levels can remain in their own text files, and I can keep using LoadString to pull them in, even on iPhone for example or XNA ?

Yes. As long as you use the mojo loadstring and not the os loadstring.


Paul - Taiphoz(Posted 2012) [#5]
how . wait wot ?

I'm using Diddy, so I think that handles importing mojo how the heck can I tell which one I am using, I didnt realize there was 2.


Raz(Posted 2012) [#6]
Use LoadString for...
another stores level data, another ship flight paths


Use LoadState for
one stores the games options coma delimited, and another stores scores.


LoadState/SaveState is for information that changes after the player starts the game (so save data, option data, scores). There is only one "file" for LoadState/SaveState so you're going to have to merge this information together.

LoadString is for predetermined information that will not change


Paul - Taiphoz(Posted 2012) [#7]
raz thanks that made sense to me.

So I need to bundle two arrays and then two values 1,1 into a single state and then save it, and load it.

I assume people have done this already, anyone care to share what their chosen methods were ?

Given that I know exactly how many scores, names, and options there are I might just pack them all in one after the other, just wondering if there is a more elegant solution.


Raz(Posted 2012) [#8]
Gfk has made a kind of emulated file system for such things I think : http://monkeycoder.co.nz/Community/posts.php?topic=1395

But personally, I just save a comma separated file and have it look for key words to know what type of information to expect next so..

settings,1,200,0,0,1,scores,23144,1215615,12612616,12612

so it would read "settings" and know the next whatever values are settings and once it reads "scores" it knows it's reading scores.


Paul - Taiphoz(Posted 2012) [#9]
Yeah, that thing is in diddy, I think I will just do my own savesate as you suggest tho before I go playing with the fake file system, wana have look under its hood first.

thanks guys this has helped a lot, and my project will be better as a result.. :)


Sub_Zero(Posted 2012) [#10]
@therevills:

I see in your testFileSystem example that you read strings without any length parameter.... Would this be equivalent to readline? or is readline() included in the file system?


therevills(Posted 2012) [#11]
read strings without any length parameter.... Would this be equivalent to readline?


Yeah I think so, I didn't write the filesystem and its been awhile since I last played with it.