Forum Topic: AS: Save and Load

(16,023 views • 121 replies)

This topic is 5 pages long. [ 1 | 2 | 3 | 4 | 5 ]

<< < > >>
None

Denvish

Reply To Post Reply & Quote

Posted at: 7/4/05 01:33 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 7/4/05 11:42 AM, Hoeloe wrote: mine dosnt work! when i click load, it only loads the level, not the score, and when i do that, it just loads the variables, not takes me back to the old part of the game!

Is your score held in the variable '_root.score' ?
Have you told it to 'gotoAndPlay(level)' once 'level' is loaded from the savefile?
You'll need to adapt the script a little if neither of these is the case

- - Flash - Music - Images - -

BBS Signature

None

wodahs

Reply To Post Reply & Quote

Posted at: 7/27/05 12:09 PM

wodahs NEUTRAL LEVEL 06

Sign-Up: 05/26/05

Posts: 97

is there anyway i can check to see if the user actually has a saved game on their hard drive?

Basically, i want it so if they have they can press a Load button and if not, it is just a movie clip that is not selectable.

I'm fine with the other codes, i just need it to check to see if there is an actually saved file on their hard drive. Thanks!


None

Toast

Reply To Post Reply & Quote

Posted at: 8/5/05 08:24 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

I know it's a bit late (VERY late ) :P
But maybe he's still looking for the answer!
If you want to know wheather OTHER people saved it, just make it send you a mail with getURL("mailto: blah blah blah","blah blah blah");


None

Inglor

Reply To Post Reply & Quote

Posted at: 8/5/05 08:28 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

1)stop being a retard toast
2)if you're going to mail, mailto: will prompt them about mailing you, what you need is to use php's mail function
3)you can just set a flag and check if it's undefined.


None

Denvish

Reply To Post Reply & Quote

Posted at: 8/5/05 09:20 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 7/27/05 12:09 PM, wodahs wrote: is there anyway i can check to see if the user actually has a saved game on their hard drive?

Basically, i want it so if they have they can press a Load button and if not, it is just a movie clip that is not selectable.

I'm fine with the other codes, i just need it to check to see if there is an actually saved file on their hard drive. Thanks!

Just attempt to pull a known variable from the savefile when the swf first loads. If the value comes back as 'undefined', then that means that no filesave exists.

var savefile = SharedObject.getLocal("yourgamename");
if(savefile.data.whatever==undefined){
//User doesn't have a savefile
}else{
//User does have a savefile
}

- - Flash - Music - Images - -

BBS Signature

None

raitendo

Reply To Post Reply & Quote

Posted at: 8/20/05 04:04 PM

raitendo NEUTRAL LEVEL 23

Sign-Up: 02/19/01

Posts: 441

does anybody know for how long the cookie stays in the system?


Shouting

fucko1

Reply To Post Reply & Quote

Posted at: 8/20/05 04:09 PM

fucko1 NEUTRAL LEVEL 28

Sign-Up: 12/16/04

Posts: 43

lol just want to see lord f the clocks the second part


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/20/05 04:16 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/20/05 04:09 PM, fucko1 wrote: lol just want to see lord f the clocks the second part

Why do you keep spamming? If you keep it up, I will report you to a mod.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

FLiXD

Reply To Post Reply & Quote

Posted at: 8/20/05 04:27 PM

FLiXD EVIL LEVEL 15

Sign-Up: 05/19/03

Posts: 156

At 8/20/05 04:16 PM, SpamBurger wrote:
At 8/20/05 04:09 PM, fucko1 wrote: lol just want to see lord f the clocks the second part
Why do you keep spamming? If you keep it up, I will report you to a mod.

oops my banfinger slipped


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 8/22/05 03:30 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

i tried using this , it works but not all the time.

onClipEvent (load) {
savefile = SharedObject.getLocal("tester");
if (savefile.data.x != undefined || savefile.data.y != undefined) {
_x = savefile.data.x;
_y = savefile.data.y;
}
trace(savefile.data.x)
trace(savefile.data.y)
}
onClipEvent (enterFrame) {
_x += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT
))*10;
_y += (Key.isDown(Key.DOWN)-Key.isDown(Key.UP))*
10;
savefile.data.x = _x;
savefile.data.y = _x;
savefile.flush();
}

im guessing it takes time to save the file, and shouldnt be done so fast over and over.

Some times my "L" key decides not to work.


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 8/22/05 03:31 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

wait nvm im retarded. i was setting both x and y to my movieclips _x coordinate. it works fine now. thanks for the tutorial. its been a while since i learned something new

Some times my "L" key decides not to work.


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 8/22/05 03:43 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

um, is there a wya to delete the file via actionscript? or do i have to search and destroy

Some times my "L" key decides not to work.


None

Denvish

Reply To Post Reply & Quote

Posted at: 8/22/05 03:52 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 8/22/05 03:43 PM, ImpotentBoy2 wrote: um, is there a wya to delete the file via actionscript? or do i have to search and destroy

It's not something I've looked into, but it seems that this should do the job

- - Flash - Music - Images - -

BBS Signature

None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 8/22/05 03:55 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

thanks. i heard of the delete functon but i didnt know it was used for files. and sorry for trip post. ill try not to do it again

Some times my "L" key decides not to work.


None

raitendo

Reply To Post Reply & Quote

Posted at: 8/27/05 02:29 PM

raitendo NEUTRAL LEVEL 23

Sign-Up: 02/19/01

Posts: 441

I'm having troubles understanding this piece of code... I managed to do it with buttons, in the _root but when I try to do it within a movie clip, I just can't get it to work. This might have to do with the fact that I don't understand much of what "var" is for...

I tried to do it like this for the save (within a movieclip)

_root.savefile:SharedObject = SharedObject.getLocal("save");
_root.savefile.data.whatever = _root.whatever;
_root.savefile.flush();

and I tried a bunch of different things for the load but this is what I've got currently (within a separate movieclip)... I removed the "var" thing because I apparently couldn't use _root with it... but I don't know, maybe I just made things worse.

_root.savefile = SharedObject.getLocal("mord_save");
_root.whatever = _root.savefile.data.whatever;

Please, if you know what I'm doing wrong, let me know!
Also, Denvish, seen a couple of your games lately, I must say I admire your flash skills. It's like we're using entirely different programs...


None

raitendo

Reply To Post Reply & Quote

Posted at: 8/27/05 02:40 PM

raitendo NEUTRAL LEVEL 23

Sign-Up: 02/19/01

Posts: 441

you know what? I suddenly got it to work, never mind...

but what was the flush() thing good for? I removed and everything seems to work fine..?

I also wanted to ask if it's possible for fone game to load a save-file from another? for example if you're making a RPG in several different parts but wants the player to be able to load his stats?

also, I asked this before but I don't know if anybody saw it, but does anybody know how long the cookie stays in the system? for a week? a year? forever?


None

DevilsSin666X

Reply To Post Reply & Quote

Posted at: 9/12/05 03:49 PM

DevilsSin666X NEUTRAL LEVEL 14

Sign-Up: 09/03/04

Posts: 408

sweet, i've been trying to find out how to do this for a while now! thanks a bunch!

[RE Club]:[SSB Crew]:[Free Hentai Exchange Club]

Want animated Signature Pics back? Copy this Sig Pic as protest!

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 9/12/05 03:52 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 8/27/05 02:40 PM, mackan_ wrote: but what was the flush() thing good for? I removed and everything seems to work fine..?

yeah, I noticed that too. I put it in there anyway

I also wanted to ask if it's possible for fone game to load a save-file from another? for example if you're making a RPG in several different parts but wants the player to be able to load his stats?

So long as the same filename is used, I don't see any reason for it not to work - haven't actually tried it, though.

also, I asked this before but I don't know if anybody saw it, but does anybody know how long the cookie stays in the system? for a week? a year? forever?

Until PC format, manual delete, or delete through AS I believe.

- - Flash - Music - Images - -

BBS Signature

None

Wretched-Raygun

Reply To Post Reply & Quote

Posted at: 9/12/05 04:02 PM

Wretched-Raygun DARK LEVEL 19

Sign-Up: 02/09/05

Posts: 1,672

Wow, Denvish you really go out of your way to help others with their actionscript problems and bring things some people didn't even know were possible!!!

If life lets you down, remember you were the fastest sperm to the egg

BBS Signature

None

Rammer

Reply To Post Reply & Quote

Posted at: 9/18/05 12:15 AM

Rammer DARK LEVEL 32

Sign-Up: 06/08/03

Posts: 4,331

At 9/12/05 03:52 PM, Denvish wrote:
At 8/27/05 02:40 PM, mackan_ wrote: but what was the flush() thing good for? I removed and everything seems to work fine..?
yeah, I noticed that too. I put it in there anyway

flush saves all the alterations you made to the shared object data. like flushing a toilet, except it keeps everything thats flushed.

also, I asked this before but I don't know if anybody saw it, but does anybody know how long the cookie stays in the system? for a week? a year? forever?
Until PC format, manual delete, or delete through AS I believe.

sharedobject.clear() will delete it, i believe. i KNOW it at least clears all the data, but im not sure if it just leaves an empty .sol file or if it actually deletes it, though. i think people were asking this before :P

snyggys


None

Starogre

Reply To Post Reply & Quote

Posted at: 10/22/05 08:07 AM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,711

Hmm.

I used cookies before, but Inglor told me to use SharedObjects because it was newer, but it's not working. Can I use this with MX, or just MX 04?

This is what I have for my load function on the first frame of the game.

onEnterFrame = function () {
var savefile = SharedObject.getLocal("SecretGameName");
if (_root.level1 == undefined) {
_root.level1 = true;
} else {
_root.level1 = savefile.data.level1;
}
if (_root.level2 == undefined) {
_root.level2 = true;
} else {
_root.level2 = savefile.data.level1;
}
if (_root.level3 == undefined) {
_root.level3 = true;
} else {
_root.level3 = savefile.data.level1;
}
};

This is what i have for my save function that extends across all but the first frame of the game.

onEnterFrame = function () {
savefile.data.level1 = _root.level1;
savefile.data.level2 = _root.level2;
savefile.data.level3 = _root.level3;
savefile.flush();
};

I even tried uploading it to my site, and trying it out, but it's not working, and I'm not sure why.

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 10/22/05 09:07 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

Why are you using level1 == undefined instead of level == undefined? Then you can have like if(lvl == 1){gotoAndPlay(1);}


None

Toast

Reply To Post Reply & Quote

Posted at: 10/22/05 09:13 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

What??? I'm unbaned? >:)
Thanks moderators.

You have two choices, try this code, or log on AIM.

onEnterFrame = function () {
var savefile = SharedObject.getLocal("SecretGameName");
if (_root.level == undefined) {
// Start new game code
}else{
gotoAndStop(_root.level/* + <a number>, so that if you have a preloader on frame one and a menu on frame 2, you can put +2 for example*/);
}
};

onEnterFrame = function () {
savefile.data.level = _root.level;
savefile.flush();
};

OR:

onEnterFrame = function () {
savefile.data.levelSO = _root.level;
savefile.flush();
};


None

Starogre

Reply To Post Reply & Quote

Posted at: 10/22/05 09:24 AM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,711

My variables shouldn't be the problem. I have things set up a certain way and i don't want to mess with it.

The variables are completely something else, it's just that my save/load isn't working.

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 10/22/05 09:33 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 10/22/05 08:07 AM, Starogre wrote: Hmm.

I used cookies before, but Inglor told me to use SharedObjects because it was newer, but it's not working. Can I use this with MX, or just MX 04?

Availability: Flash Player 6

This is what I have for my load function on the first frame of the game.
Code

The one big problem that I can see is in your Load function:

_root.level2 = savefile.data.level1;
...........
_root.level3 = savefile.data.level1;

Surely they should read:

_root.level2 = savefile.data.level2;
.............
_root.level3 = savefile.data.level3;

Other than that, try using '1' rather than 'true' and '0' rather than 'false'.

- - Flash - Music - Images - -

BBS Signature

None

Starogre

Reply To Post Reply & Quote

Posted at: 10/22/05 10:12 AM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,711

Ya my load function is pretty screwed, but I think my autosave thing isn't working out. I tried using cookies the same way and it didn't work. Right now i'm only testing to see if it remembers that i beat level 1 so level 2 and 3 shouldn't matter at the moment. I am also changing it to a load button instead of autoloading. I think that would work better anyways.

BBS Signature

None

Valchrist

Reply To Post Reply & Quote

Posted at: 10/24/05 03:29 PM

Valchrist EVIL LEVEL 05

Sign-Up: 07/23/04

Posts: 43

Ok, first of all, the thing with the Flush command: Windows has a funny way of holding on to tasks and performing them later, when it is more convenient. Flush forces windows to perform your save action when you tell it to. Otherwise, if you don't have it in there, it might not save the file before you attempt to load it, and you will be trying to load a file that doesn't exist. Kind of like flash drives. The "Safely remove hardware" thing is the same as a flush. It forces Windows to save anything that you've said to put on the flash drive or take off of it. Hopefully that clears some things up.

I actually have a question on the SharedObject. For the filename of the .sol file, can you use a variable? I'm trying to make a character sheet for an RPG I play, and I want a button that will save the character sheet as the name the character types into the "name" text box. This way they can have multiple characters and can type in the name of the character sheet they want to load before they click the load button.

Thanks for the help, and great post!


None

Gruntmyster

Reply To Post Reply & Quote

Posted at: 10/27/05 10:31 PM

Gruntmyster NEUTRAL LEVEL 06

Sign-Up: 12/12/03

Posts: 21

Sorry to bump the thread...
For the "SharedObject.getLocal("yourgamename");"

Do you have to add an extension to yougamename, such as .swf or .sol?

Thanks,
Kardin


None

Toast

Reply To Post Reply & Quote

Posted at: 10/28/05 04:15 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

At 10/27/05 10:31 PM, Gruntmyster wrote:
Do you have to add an extension to yougamename, such as .swf or .sol?

I don't think you have to add extensions. I think it even works if you just type blanakgjnbgajnlgba b.


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 11/22/05 02:47 AM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,015

hey, denvish! cud u help me do some saving? i want to save 5 files at one time, like you saves score + level, i want o save the best score, the secoond best score, the third best score, the fourth and the fifth best scores, how can i do this because your script doesnt work

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 09:10 AM

<< Back

This topic is 5 pages long. [ 1 | 2 | 3 | 4 | 5 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!