00:00
00:00
Newgrounds Background Image Theme

sosualadies just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Save and Load

37,818 Views | 127 Replies
New Topic Respond to this Topic

Response to AS: Save and Load 2005-07-27 12:09:13


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!

Response to AS: Save and Load 2005-08-05 08:24:44


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");


BBS Signature

Response to AS: Save and Load 2005-08-05 08:28:10


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.

Response to AS: Save and Load 2005-08-05 09:20:17


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

Response to AS: Save and Load 2005-08-20 16:04:47


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

Response to AS: Save and Load 2005-08-20 16:09:50


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

Response to AS: Save and Load 2005-08-20 16:27:31


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

Response to AS: Save and Load 2005-08-22 15:30:03


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.

Response to AS: Save and Load 2005-08-22 15:31:33


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

Response to AS: Save and Load 2005-08-22 15:43:24


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

Response to AS: Save and Load 2005-08-22 15:52:39


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

Response to AS: Save and Load 2005-08-22 15:55:14


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

Response to AS: Save and Load 2005-08-27 14:29:36


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...

Response to AS: Save and Load 2005-08-27 14:40:25


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?

Response to AS: Save and Load 2005-09-12 15:49:02


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

Response to AS: Save and Load 2005-09-12 15:52:02


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

Response to AS: Save and Load 2005-09-12 16:02:37


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

Response to AS: Save and Load 2005-09-18 00:15:55


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

Response to AS: Save and Load 2005-10-22 08:07:12


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.


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature

Response to AS: Save and Load 2005-10-22 09:07:35


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


BBS Signature

Response to AS: Save and Load 2005-10-22 09:13:42


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();
};


BBS Signature

Response to AS: Save and Load 2005-10-22 09:24:07


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.


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature

Response to AS: Save and Load 2005-10-22 09:33:37


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

Response to AS: Save and Load 2005-10-22 10:12:28


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.


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature

Response to AS: Save and Load 2005-10-24 15:29:26


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!

Response to AS: Save and Load 2005-10-27 22:31:44


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

Response to AS: Save and Load 2005-10-28 04:15:38


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.


BBS Signature

Response to AS: Save and Load 2005-11-22 02:47:23


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


BBS Signature

Response to AS: Save and Load 2005-11-22 03:09:29


At 11/22/05 02:47 AM, Hoeloe wrote: hey, denvish!

i could help =D
saving move variables is realy easy =D

var sav:SharedObject = SharedObject.getLocal("saveName");
sav.data.var1 = 'some value';
sav.data.var2 = "some more data";
sav.data.var3 = "i think you get the picture..";
/*to save more things just add 'sav.data.name' you can save info from a variable like this
sav.data.var4 = _root.someVar
and then to load its just as simple
first declair you what SharedObeject you want to load info from*/
var sav:SharedObject = SharedObject.getLocal("saveName");
_root.aVar = sav.data.var1;
trace(sav.data.var1+" "+sav.data.var2+" "+sav.data.var3)

/*
just treat every a sharedObject variable as a normal variable =D thats what i do = )
*/
simple enough

Response to AS: Save and Load 2005-11-22 03:15:18


i dont think you understand. i want to do like a hi score table but all the scores are set by the player, and the scores are not set across the internet


BBS Signature