Page 2 of 2

Re: Saving and Loading

PostPosted: Fri Oct 17, 2008 10:16 am
by GuybrushThreepwood
I dont get it... could someone make a tutorial please? :mrgreen:

Re: Saving and Loading

PostPosted: Fri Oct 17, 2008 11:47 am
by Bee-Ant
GE already has a built in tutorial about this. "Updating SCORE" or something...
This is what I mean with hard to explain... :roll:

Re: Saving and Loading

PostPosted: Sat Oct 25, 2008 1:19 am
by j2graves
I only know the global integer one =(

Re: Saving and Loading

PostPosted: Sat Oct 25, 2008 9:05 am
by Kalladdolf
lol, I'm sorry to say that, but I read this post for the first time. As I scrolled down I more and more became like :roll: .
:wink:
Never mind that now, lemme explain:
There are global variables (which apply to all actors in the game)
and actor variables (which only apply to only one actor)
Example for global variable: You set a gravity which can change during the game. But you'd like every actor to obey its force.
Example for actor variable: Your hero finds himself in front of a bunch of hideous enemies. He starts killing them. Everyone has a certain health. But the "actor variable" has the advantage that you don't have to create a new health variable for each individual clone, but only one variable for everyone. If you shoot him only his health goes down and he dies. With a global variable, every enemy would've died when you killed only one! That's kinda funny (give or take a little) but it doesn't serve the purpose.

So much for the variables.
If you want script examples, just ask for 'em.

Now, let's turn our attention to the saving/loading.
In this case, we want to save the level we're in.
First create a global variable called "level" and the save group called "data" (this is important!) and the level variable gets higher every time you complete a level.
Collision -> goal ->
Code: Select all
level = level + 1;

Still with me? good.
Now add a saving button.
Add the event "mouse button down (left)" and select the Script Editor as action.
Then (if you're not familiar with the scripting) open the variable-and-function panel.
You'll find a variety of stuff you can select there (including your own level variable which you should be proud of :wink: ).
Select the SaveVars function. A window will appear asking for the variable, the group and the file it should be saved in.
Now you can decide what to enter. Call the file whatever you want, just MAKE SURE that it's exactly the same file when you LOAD the variables. Select the "data" save group which you've created previously along with your level variable (if you still remember XD). Groups are there for your variables in order not to get messed up. Once you completed that step, click "ok". The code should basically look like that:
Code: Select all
saveVars("data", "data");


That's done it! You've saved your level! (This is a very simple way, believe it or not).

Now to the loading:

Create a load button
MouseButton down -> LoadButton
Code: Select all
loadVars("data", "data");


And now you've loaded the level variable.
From there, you can let your actor take certain actions depending on the level variable, such as changing his position if the level equals a certain number.

I hope that helped.
-K@ll

Re: Saving and Loading

PostPosted: Sat Oct 25, 2008 8:34 pm
by BlarghNRawr
hey thanks :D :lol:

Re: Saving and Loading

PostPosted: Sat Nov 08, 2008 7:33 pm
by Kalladdolf
well, GT, is that what you had in mind?

Re: Saving and Loading

PostPosted: Sat Nov 08, 2008 9:58 pm
by GuybrushThreepwood
Collision -> goal ->
Code: Select all
level = level + 1;



Were does that go? :mrgreen:

Re: Saving and Loading

PostPosted: Sun Nov 09, 2008 3:29 am
by BlarghNRawr
on collision with goal

Re: Saving and Loading

PostPosted: Sun Nov 09, 2008 5:05 am
by DilloDude
Or whatever event finishes the level.

Re: Saving and Loading

PostPosted: Sun Nov 09, 2008 6:13 am
by GuybrushThreepwood
see Kalladdolf, i dont have levels, its a point an click/puzzle/adventure game (probably should of mentioned that earlier :mrgreen: )

Re: Saving and Loading

PostPosted: Sun Nov 09, 2008 7:51 am
by DilloDude
Exactly. This basic example deals with the situation where you just need to save which level you're up to. In a more complicated example, you will need to save a lot more things, such as inventory, which things have been collected (if there's only 1 of something, and you have it, you don't want it to still be there), which places you have visited, where you are now, what goals you have achieved etc. But the basic process is the same: create variables to store everything, put them in a save group; when things happen, update the variabes; when you save, save the group; when you load, load the group and set stuff up according to those variables.