I've been looking through lots of tutorials and haven't been able to figure out how to save information and load it from an .ini file. Can anyone explain to me step by step how to save my global values and load them thoroughly? Thanx in advance!
Sure thing. This will an explaination of MMF, but I don't think TGF varies too much at all:
There are just a few simple steps with INIs, which follow in this exact order:
Set the file
Set the group
Set the item
Get/Set the value
Setting the file:
Depends where you want to put it, but I recommend that you don't annoy the player by sticking in some random folder or whatever. Instead, put it in the game's directory. So your file setting action will be:
Set current file to (Appdrive$ + Appdir$ + "\<name of ini>.ini")
Setting the group:
Groups just let you organise your items into related areas. You can easily just scrape by with 1 group, as you get more comfortable you can organise your INIs more. Your groups setting action will be:
Set current group to "Saved"
Setting the item:
The items are names for the values you are storing. You refer to an item to get its value.
Your item setting action will be:
Set current item to <anything really, eg. "Level">
Setting the value of an item, or "saving"
To save some kind of data to be loaded back into the game at a later time, the action is:
Set value of current item to <desired global value, or any value for that matter>
Getting the value of an item, or "loading"
When you load your game, for each of the global values you need, set to the relevent item, then use the action:
Set value of <desired global value, or any value for that matter> to value of current item
So an example event for loading a game would be:
1.
Button "Load" is clicked:
▪ Set current file to Appdrive$+Appdir$+"\Saved.ini"
▪ Set current group to "Slot1"
▪ Set current item to "Level"
▪ Set Global Value A to value of current item
▪ Set current item to "Ammo"
▪ Set Global Value B to value of current item
▪ Set current item to "Weapon"
▪ Set Global Value C to value of current item
▪ Set current item to "Score"
▪ Set score of player 1 to value of current item
Similarly, an event for saving the equivelent game would be:
1.
Button "Save" is clicked:
▪ Set current file to Appdrive$+Appdir$+"\Saved.ini"
▪ Set current group to "Slot1"
▪ Set current item to "Level"
▪ Set value of current item to Global Value A
▪ Set current item to "Ammo"
▪ Set value of current item to Global Value B
▪ Set current item to "Weapon"
▪ Set value of current item to Global Value C
▪ Set current item to "Score"
▪ Set value of current item to score of player 1
There. Hope I helped.
Edited by the Author.
n/a
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
24th April, 2004 at 03:44:51 -
In the unlikely case that Biax doesn't know what he's talking about here's an example at the clickteam knowledge base.
Hey, I had the same problem the other day, but I experimeted i bit and figured it out. Im not sure how to do global values, but global counters works just as good. this is in TGF by the way.
Level editor:
- create an INI file, name it "save" or something.
- Create a counter object, and make it global (rightclick, choose object preferences and check the global to the entire game)
Event editor:
-Upon pressing "Q" add to counter 1
-Upon pressing "W" set the value of the counter equal the ini. or just put this in under the counter "value of( "Ini" )" (remeber, add this under the counter object, not under the ini file.
-Upon pressing "E" set item value of INI to the value of the counter. or just paste this in under the INI (not under the counter this time) " value( "cash counter" )"
there you go. Now try it out. "Q" adds to the counter, "W" loads the counter, "E" saves the counter. Now add some numbers, save it, exit and press "W" to load them up.