Page 1 of 2

whats the script editor code for saving

PostPosted: Sun Jul 11, 2010 8:09 am
by pizbi
Does anyone know how I can make a level checkpoint save in a game? :?

Re: whats the script editor code for saving

PostPosted: Sun Jul 11, 2010 12:07 pm
by Bee-Ant
1. Make at least 2 variables, PosX and PosY to determine the player X and Y position. If you don't know how to make variables, go to Script Editor or Global code, I have posted the picture of how to add it bellow. Save both of them in a group called "data".

2. When you reach certain location of checkpoint, for instance you get the checkpoint by Colliding with some Checkpoint actor...then
YourPlayerName->Collision->CheckpointActor->ScriptEditor :
Code: Select all
PosX=x; //assign the x position
PosY=y; //assign the y position
saveVars("YourDataFileName.dat","data"); //save your data into a file


3. When your player die, and you want to recreate your player to the checkpoint location, for instance you want to directly create the player just after he's died...
YourPlayerName->DestroyActor->ScriptEditor :
Code: Select all
CreateActor("YourPlayerName", "YourPlayerAnimation", "(none)", "(none)", PosX, PosY, true); //create your player to the checkpoint location
view.x=PosX-320; //assign the view x position
view.y=PosY-240; //assign the view y position


4. Next time, when you load the game, and want to continue your checkpoint location
view->CreateActor->ScriptEditor :
Code: Select all
loadVars("YourDataFileName.dat", "data"); //load your saved data from file
YourPlayerName.x=PosX;
YourPlayerName.y=PosY;
view.x=PosX-320;
view.y=PosY-240;

Hope helps :D

Re: whats the script editor code for saving

PostPosted: Mon Jul 12, 2010 10:26 pm
by Camper1995
Thats one way to make if you want your game be loaded when you start new one,

..if you dont wanna load it when you start new game and you only want to save
player during the game, dont make it so.

Create 2 sensors called viewMove and PlayerSPAWN (call it however you want, its just example)

So now, when the player hit the checkpoint, move actor viewMove to view

and actor PlayerSPAWN to player.

That's all. Then just when you die, move player to PlayerSPAWN and view to viewMove.

I hope it helps. xD

:)

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 5:09 am
by Bee-Ant
Camper1995 wrote:Thats one way to make if you want your game be loaded when you start new one

Bee-Ant wrote:When your player die, and you want to recreate your player to the checkpoint location, for instance you want to directly create the player just after he's died...

I posted code for any way to load the checkpoint, not only when loading the level...

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 9:14 am
by savvy
whoa dudes your making this waaaaaay too complex, too much code. ill simplify on what they said.
basically, create 2 variables. (playerx and playery) then when you touch the checkpoint put in this code:
Code: Select all
playerx=player.x;
playery=player.y

then save your variables(in the same file)

if u want it to load then when your character loads then just add on destroy actor:
(1st load the variables)
Code: Select all
player.x=playerx;
player.y=playery;


any questions?

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 10:28 am
by Hblade
My idea would to be, make a little flag thing, (Or any checkpoint art), then when the player collides into it, use this code

FIRST: Make 4 variables
          VARIABLES:
          px
          py
          vx
          vy
These stand for Player x,y, and View x,y.

Now use this code on the collision with the checkpoint
Code: Select all
px = player.x;
py = player.y;
vx = view.x;
vy = view.y;


Now, on the death of the player, (Instead of using Destroy Actor("Event Actor") when his health is low, just use this)
Code: Select all
if (player_hp<=0)
{
    x = px;
    y = py;
    view.x = vx;
    view.y = vy;
    player_hp = player_maxhp
}

This code is assuming you have health in the game :3 :D Hope this helped :D

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 12:05 pm
by savvy
Yah, that is basically the same as mine except with hp included in the equation and no dying.
OK, basically there are plenty of ways to do this but mine and Hblades. some of the codes used in saving can be over complicated and hence easily shortened. Good luck. :D

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 12:07 pm
by savvy
i apologise Beeant for this but, your way is really stupidly complicated for someone just learning to save.

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 12:54 pm
by Hblade
Lol, I'll agree that bee-ant did over complicate things xD But I think thats just because he's used to coding "Professionally" :o

To me, anything that gets the job done works lol... I mean its not like a few lines could cause more lag o.o

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 12:59 pm
by jimmynewguy
woah wait a minute here....what is complicated about bee-ants, and where did all this hate come from? First of all savvy (not starting an argument here) but your code doesn't compensate for the view. The view would just stay where you died. Secondly this is a more effecient way then saving the view code because your just centering the view on the player, nothing is complicated there. Just think a little before you go around saying peoples codes are "stupidly complicated" when your code doesn't even finish the job. I cant stand people ripping on how others code. Everyone does it differently and it doesn't matter (to an extent...) how its done if it works, as long as it gets the job done.

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 1:43 pm
by savvy
Hey, if he/shes just learning how to use save functions then that means that he/she is probably still using parent actor functions for the view and player so mine would work, plus i never slagged of beeant, i merely said it was a bit complicated for someone just leartning to use thoses functions. as Hblade will probably agree.

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 1:44 pm
by savvy
AND, Hblade, i agree..any code which works without glitch is good enough until you start doing mega complex things

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 2:11 pm
by Hblade
yeah xD

Jimmy, I think you got the wrong idea on Savvy lol, he was just insinuating that for a beginner, Bee-Ants code might be a little confusing xD

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 2:19 pm
by Bee-Ant
I have tried to post the code as simple as I could...
I was focus on the topic's title "whats the script editor code for saving", so it supposed to use "saveVars("filename.dat","groupname");"
And the "whats the script editor code for loading", it would be "loadVars("filename.dat","groupname");"
Seems complicated or not, it can't be helped...it's the default code to do them...

savvy wrote:if he/she

I'm "he" :mrgreen:

Re: whats the script editor code for saving

PostPosted: Tue Jul 13, 2010 2:21 pm
by Hblade
lol. I understand where your getting that from bee-Ant :o