ive been using this program for years and im not bad at it (apart from being a little crappy at doing graphics , but one thing ive never got my head round is how to do savegames, how would i be able to do a savegame system where with a 'start' and 'continue' button on the main title screen, where start will start a new game, and continue will load at the point (or even just the level) that i last used a 'save' function that i could build into my game
The key to it all is understanding that there isn't a 'save/load game' action in TGF. It's not quite that simple.
You see, TGF/MMF doesn't know what you want to save. It's not got any brains, it has no idea what you're using it to create, it just does what you tell it.
So we need to tell TGF what to save and where to save it, AND how to load it back again.
What we use INI Object for is saving the information onto the hard disk in a file. There are lots of extensions that can do this, and they all have their own little pros and cons - array object, associative array object, datastore, Binary Object, Edit Object, List Object, ComboList Object, you name it. But for now we'll just use INI, lol.
Let's suppose we're doing a simple little platformer. We've got 12 big levels, but each has three save points - one right at the start, one in the middle, and one just before the boss of that level.
The player has a lives counter, a health counter, an ammo counter and a magic counter.
So let's think of what to save:
~Level Number (1 to 12)
~Save Point (1 to 3)
~Lives
~Health
~Ammo
~Magic
This is pretty basic. So we'll make it so when the player stands on a save point and presses 'S' it saves the INI file:
This tells TGF where to save everything.
We may as well tell it this at the start so we don't have to bother later.
The appdrive/dir stuff just makes sure it saves it in the same place as
the .exe file of your game.
Start Of Level
-INI Object: Set file to appdrive$+appdir$+"saves.ini"
When the player presses 's', we tell TGF to save the values in
the INI file. Note that it hasn't saved the player's save point yet.
We'll do that after this
Player Presses "S"
--INI Object: Set "Level" to 'level'
--INI Object: Set "Lives" to 'lives'
--INI Object: Set "Health" to 'value("health counter")'
--INI Object: Set "Ammo" to 'value("ammo counter")'
--INI Object: Set "Magic" to 'value("magic counter")'
These three events just check which save point the player
is using.
Player Presses "S"
+Player is overlapping 'Savepoint 1'
--INI Object: Set "Save Point" to '1'
Player Presses "S"
+Player is overlapping 'Savepoint 2'
--INI Object: Set "Save Point" to '2'
Player Presses "S"
+Player is overlapping 'Savepoint 3'
--INI Object: Set "Save Point" to '3'
Do you see how that works? It's just putting numbers inside INI Object and naming them. INI Object then saves them onto the hard disk.
Now we need to make it so when the player presses 'L', it loads that INI file again.
When the player presses 'L', it sets Global Value A to 1 and
loads the level number that we saved. The reason we used the global
value is so when the level starts, it can activate the events for
loading the level. You'll see how this works in a second.
Player Presses "L"
--Set Global Value A to '1'
--Jump to Level 'ItemValue( "Ini", "Level" )'
Here's the command to load all the values (except the save point).
Start Of Level
+Global Value A = 1
--Set Number of Lives to 'ItemValue( "Ini", "Lives" )'
--Set value of 'Health' counter to 'ItemValue( "Ini", "Health" )'
--Set value of 'ammo' counter to 'ItemValue( "Ini", "Ammo" )'
--Set value of 'magic' counter to 'ItemValue( "Ini", "Magic" )'
These three events are to put the player in the right
position for the save point he was in last time.
Start Of Level
+Global Value A = 1
+'ItemValue( "Ini", "Save Point" )' == 1
--Set player position to (position of save point 1)
Start Of Level
+Global Value A = 1
+'ItemValue( "Ini", "Save Point" )' == 2
--Set player position to (position of save point 2)
Start Of Level
+Global Value A = 1
+'ItemValue( "Ini", "Save Point" )' == 3
--Set player position to (position of save point 3)
That's it!
So long as these events are in every level, it'll work.