knucklecrunchgames wrote:OK. On my game You press new game play the game and then you get tired of playing. How do I save it to load the dat file it was saved on
lcl wrote:knucklecrunchgames wrote:OK. On my game You press new game play the game and then you get tired of playing. How do I save it to load the dat file it was saved on
Basically all you need is to have variables with a save group for all the things you want to save, player position, view position, score, etc.
and then you use saveVars() to save them, and when loadVars() to load them.
posX = player.x;
posY = player.y;
saveVars("gamesaves.sav", "playerPosition");
loadVars("gamesaves.sav", "playerPosition");
player.x = posX;
player.y = posY;
lcl wrote:Using saveVars and loadVars has been explained very many times on this forum.
You should try to find out by yourself before asking questions, because there really is answers to most of the simpler questions people have.
I'll explain it to you now shortly.
You know what variables are, right?
So, for saving the player actors position (values of x and y), you have to first create two global integer variables with a save group.
You can name the save group whatever you want, an example would be playerPosition.
Then, you write this code to the script editor event where you want to save the game:
- Code: Select all
posX = player.x;
posY = player.y;
saveVars("gamesaves.sav", "playerPosition");
The position will be saved to a file named gamesaves.sav.
This code is all you need for saving the player position provided that your variables are named posX and posY, and that they belong to a save group named playerPosition, and that your main actor is called player.
Then when you want to load the values, and set the player actor back to the saved position, you just have to write this:
- Code: Select all
loadVars("gamesaves.sav", "playerPosition");
player.x = posX;
player.y = posY;
This is all you need for saving and loading an actors coordinates.
I hope that you think through the code, because just copying it to your game won't help you learn anything, because learning code is possible only after understanding it.
If you don't understand the code, say it, and I'll explain it to you bit by bit so that you will understand and learn it.
lcl wrote:Basically variables are named numbers. You can give them any values you want, only depending on their type.
Integer variables can only have integer values, and double and float variables can have real numbers, e.g. floating point values.
Read more from here: viewtopic.php?f=27&t=6834&p=48846&hilit=keywords+and+functions#p48846
The whole post is quite useful, but for understanding variables, you should read at least the explanation under these subheads:
-double
-int
-operators
and I also recommend reading about if condition (it's just above the 'operators' subhead).
knucklecrunchgames wrote:Man you are great thankyou lcl +1 again tomorrow
Users browsing this forum: No registered users and 1 guest