Page 1 of 1

How to save player parameters on game exit

PostPosted: Mon May 28, 2012 10:46 am
by lverona
Hey guys!
I read the tutorial on how to save/load parameters of player - no questions there. Question is - how to save parameters on exit?

Re: How to save player parameters on game exit

PostPosted: Mon May 28, 2012 2:16 pm
by Hblade
You mean like pressing escape?

Go to the settings place where you can change the resolution and all that, you should see an option to disable the escape button, make sure you disable the ESC button to escale. Now, go to the view actor and go to Events -- Add -- KeyDown -- Esc -- Script Editor and place in this code.


But first: Go to Variables, click ADD, and make it like this:
arrays.png

Make sure array is set to yes and value is 4

now heres the code that should go in :)
Code: Select all
//replace the text
//player with your players name

playerVars[0]=player.x;
playerVars[1]=player.y;
// ^ Saves the players X and y

playerVars[2]=view.x;
playerVars[3]=view.y;
// ^ Saves the views x and y positions

saveVars("gameSave.sav", "posiSave");
ExitGame();
;

Now when you press escape you can exit the game and save the variables too :)

I'm pretty sure you know how to load the variables right? If not let me know and Ill explain.

Actually I'll go ahead and explain it.

Alright, you know how we have playerVars[0]=player.x? When you load a variable, you have to reverse it, so it looks like this instead. player.x=playerVars[0]. So therefor, on the view, go to create actor and put in this code:
Code: Select all
loadVars("gameSave.sav", "posiSave");
player.X=playerVars[0];
player.y=playerVars[1];
// ^ Loads the players X and y

view.X=playerVars[2];
view.y=playerVars[3];
// ^ Loads the views x and y positions


There might be spelling errors, so make sure everything is correct before getting excited and just copying and pasting ;P

Please make sure you actually read this xD
Otherwise you'd end up confused o.o

Re: How to save player parameters on game exit

PostPosted: Tue May 29, 2012 7:15 am
by lverona
Thank you! Works )

Re: How to save player parameters on game exit

PostPosted: Tue May 29, 2012 3:56 pm
by Hblade
awesome :) glad to hear!