whats the script editor code for saving

Non-platform specific questions.

whats the script editor code for saving

Postby pizbi » Sun Jul 11, 2010 8:09 am

Does anyone know how I can make a level checkpoint save in a game? :?
User avatar
pizbi
 
Posts: 37
Joined: Thu Jul 08, 2010 3:36 am
Location: oregon
Score: 7 Give a positive score

Re: whats the script editor code for saving

Postby Bee-Ant » Sun Jul 11, 2010 12:07 pm

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
Attachments
vars.png
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: whats the script editor code for saving

Postby Camper1995 » Mon Jul 12, 2010 10:26 pm

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

:)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby Bee-Ant » Tue Jul 13, 2010 5:09 am

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...
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: whats the script editor code for saving

Postby savvy » Tue Jul 13, 2010 9:14 am

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?
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby Hblade » Tue Jul 13, 2010 10:28 am

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
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: whats the script editor code for saving

Postby savvy » Tue Jul 13, 2010 12:05 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby savvy » Tue Jul 13, 2010 12:07 pm

i apologise Beeant for this but, your way is really stupidly complicated for someone just learning to save.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby Hblade » Tue Jul 13, 2010 12:54 pm

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
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: whats the script editor code for saving

Postby jimmynewguy » Tue Jul 13, 2010 12:59 pm

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.
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: whats the script editor code for saving

Postby savvy » Tue Jul 13, 2010 1:43 pm

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.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby savvy » Tue Jul 13, 2010 1:44 pm

AND, Hblade, i agree..any code which works without glitch is good enough until you start doing mega complex things
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: whats the script editor code for saving

Postby Hblade » Tue Jul 13, 2010 2:11 pm

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
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: whats the script editor code for saving

Postby Bee-Ant » Tue Jul 13, 2010 2:19 pm

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:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: whats the script editor code for saving

Postby Hblade » Tue Jul 13, 2010 2:21 pm

lol. I understand where your getting that from bee-Ant :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

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest