Game Development Community

Simple way to save some attribute...

by Andrea Farid Marsili · in Torque Game Builder · 08/09/2010 (8:13 pm) · 4 replies

In my game I'll need to save only some attribute.
So you know some tutorial which explain how to save and load attribute or/and share it through different level?
Thanks to all

#1
08/10/2010 (4:07 am)
You could just use global variables to save it across different levels.

If you need to save it across different runs of the executable, you can use export().

$mygame::variable = 0;
$mygame::otherVar = "Hello";
export( "$mygame::*", "gamevars.cs" );

... somewhere during game startup ...
exec( "gamevars.cs" );
#2
08/10/2010 (7:57 am)
So if i want to save and then load some variables I only need to do this:
Example in pseudocode

if "player" collide with "door"

export all $mygame variable into a file named "gamevars.cs"

And if I want to load this variable I must write this in my "loadGame" button code:

exec("gamevars.cs")

then if $mygame variable have value 1 (for example) go to level two.

Wrong?
#3
08/10/2010 (9:38 am)
Yes that's correct, but a better way would be doing it the way below just in case the person wants to start a new game.

Have a main menu with new game, load game etc. When the person loads a new game then execute gamevars.cs
#4
08/10/2010 (10:31 am)
Yes I was talking about the LoadGame button. The NewGameButton will reset all the variables.