How to save player parameters on game exit

Non-platform specific questions.

How to save player parameters on game exit

Postby lverona » Mon May 28, 2012 10:46 am

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?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to save player parameters on game exit

Postby Hblade » Mon May 28, 2012 2:16 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: How to save player parameters on game exit

Postby lverona » Tue May 29, 2012 7:15 am

Thank you! Works )
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to save player parameters on game exit

Postby Hblade » Tue May 29, 2012 3:56 pm

awesome :) glad to hear!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron