Forum Topic: AS: Save and Load

(16,021 views • 121 replies)

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

<< < > >>
None

shazwoogle

Reply To Post Reply & Quote

Posted at: 11/22/05 03:09 AM

shazwoogle NEUTRAL LEVEL 11

Sign-Up: 09/27/04

Posts: 2,681

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


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 11/22/05 03:15 AM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,015

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

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

BBS Signature

None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/20/05 08:20 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

when a variable is saved, is it only accessible from that swf file? or can it be accessed through another?

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


None

Denvish

Reply To Post Reply & Quote

Posted at: 12/20/05 08:24 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 12/20/05 08:20 PM, ImpotentBoy2 wrote: when a variable is saved, is it only accessible from that swf file? or can it be accessed through another?

the sol file is saved in a folder on your PC with the filename on it - eg, for a game called Chalice for which the swf is at:

D:\\_Working\ Working\ Flash\Chalice\ Chalice07.swf

the sol path will be

C:\Documents and Settings\ USERNAME\ Application Data\ Macromedia\ Flash Player\ localhost\ _Working\ Working\ Flash\ Chalice\ Chalice07.swf

So basically, unless the swf has exactly the same filename and path, no, the shared objects won't work.
As far as I know.

- - Flash - Music - Images - -

BBS Signature

None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/20/05 08:25 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

gah! i really need to learn php

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


None

Mitch-Mac

Reply To Post Reply & Quote

Posted at: 12/20/05 09:11 PM

Mitch-Mac LIGHT LEVEL 10

Sign-Up: 07/05/03

Posts: 911

I havnt been to newgrounds in so long, anyway can anyone tell me whats wrong with this?

LOAD:

on (press) {
var game = SharedObject.getLocal("mitchsrpg");
if (game.data.name == undefined) {
_root.hp = 50;
_root.hp2 = 50;
_root.gotoAndStop(2);
} else {
_root.attack = game.data.attack;
_root.hp = game.data.hp;
_root.mp = game.data.mp;
_root.hp2 = game.data.hp2;
_root.mp2 = game.data.mp2;
_root.defence = game.data.defence;
_root.lvl = game.data.lvl;
_root.nextlvl = game.data.nextlvl;
_root.magic = game.data.magic;
_root.exp = game.data.exp;
_root.gotoAndStop(3);
}
}

SAVE:

on (release) {
game.data.hp = _root.hp;
game.data.hp2 = _root.hp2;
game.data.mp = _root.mp;
game.data.mp2 = _root.mp2;
game.data.attack = _root.attack;
game.data.defence = _root.defence;
game.data.lvl = _root.lvl;
game.data.nextlvl = _root.nextlvl;
game.data.magic = _root.magic;
game.data.exp = _root.exp;
game.flush();
}


None

fwe

Reply To Post Reply & Quote

Posted at: 12/20/05 09:15 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

You should also define game in the save button.

Unless you do _root.game = bleh on the load, which will make it accesible if you put _root on teh save, but then you'd have to load it before you save. So go with my first option

wtfbbqhax


None

Mitch-Mac

Reply To Post Reply & Quote

Posted at: 12/20/05 09:18 PM

Mitch-Mac LIGHT LEVEL 10

Sign-Up: 07/05/03

Posts: 911

Originally it was this before I looked at the first page of this tutorail ( this didnt work either and it contains alot of extra stuff I dont know why I put it there)

LOAD:

on (press) {
game = SharedObject.getLocal("mydata");
if (game.data.name == undefined) {
_root.hp = 50;
_root.hp2 = 50;
_root.gotoAndStop(2);
} else {
attack = game.data.attack;
hp = game.data.hp;
mp = game.data.mp;
hp2 = game.data.hp2;
mp2 = game.data.mp2;
defence = game.data.defence;
lvl = game.data.lvl;
nextlvl = game.data.nextlvl;
magic = game.data.magic;
exp = game.data.exp;
_root.attack = attack;
_root.lvl = lvl;
_root.nextlvl = nextlvl;
_root.hp = hp;
_root.mp2 = mp2;
_root.mp = mp;
_root.hp2 = hp2;
_root.defence = defence;
_root.magic = magic;
_root.exp = exp;
_root.gotoAndStop(3);
}
}

SAVE:

on (press) {
game = SharedObject.getLocal("mydata");
attack = _root.attack;
lvl = _root.lvl;
nextlvl = _root.nextlvl;
defence = _root.defence;
magic = _root.magic;
exp = _root.exp;
hp = _root.hp;
hp2 = _root.hp2;
mp2 = _root.mp2;
mp = _root.mp;
game.data.hp = hp;
game.data.hp2 = hp2;
game.data.mp = mp;
game.data.mp2 = mp2;
game.data.attack = attack;
game.data.defence = defence;
game.data.lvl = lvl;
game.data.nextlvl = nextlvl;
game.data.magic = magic;
game.data.exp = exp;
game.flush();
}


None

fwe

Reply To Post Reply & Quote

Posted at: 12/20/05 09:25 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

That code looks functional to me. I don't sense a problem

wtfbbqhax


None

Mitch-Mac

Reply To Post Reply & Quote

Posted at: 12/20/05 09:35 PM

Mitch-Mac LIGHT LEVEL 10

Sign-Up: 07/05/03

Posts: 911

I'm workin on something I havnt worked on in like 2 months, unless the file is currupt or flash player has changed sence then. As far as I can remeber, it used to work, and now it doesn't.


None

Mitch-Mac

Reply To Post Reply & Quote

Posted at: 12/21/05 03:05 PM

Mitch-Mac LIGHT LEVEL 10

Sign-Up: 07/05/03

Posts: 911

-Bump


None

fwe

Reply To Post Reply & Quote

Posted at: 12/21/05 03:26 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

Are you using flash below 7?

I think it's like this in earlier versions

sharedObject.getlocal()

I colud be mistaken

wtfbbqhax


None

Red-Fruity-Loops

Reply To Post Reply & Quote

Posted at: 1/9/06 01:41 PM

Red-Fruity-Loops FAB LEVEL 07

Sign-Up: 03/07/05

Posts: 114

I need help i followed the the tut but it doesn't work the output says the code is ok so i must have put everything in the right place here is the code

Timeline load code:

//Specify the save file to use
var savefile = SharedObject.getLocal("Counter");
//Grab the level and score held in the file, and assign them to variables
_root.hrs = savefile.data.hrs;
_root.min = savefile.data.min;
_root.sec = savefile.data.sec;
//If they don't exist, (ie first run), set variables to zero
if(savefile.data.score==undefined){
_root.hrse=0;
_root.min=0;
_root.sec=0;
}

Load button:

on (press){
var savefile = SharedObject.getLocal("Counter");
if(savefile.data.score==undefined){
_root.hrs=0;
_root.min=0;
_root.sec=0;
}else{
_root.score=savefile.data.score;
}
}

Save button:

on (press){
savefile.data.score = _root.hrs;
savefile.data.score=_root.min;
savefile.data.score=_root.sec;
savefile.flush();
}

Please help?

Note: The timeline code is on layer 2 and the save and load layer 1. all in 1 frame.


None

healing

Reply To Post Reply & Quote

Posted at: 1/11/06 03:36 AM

healing NEUTRAL LEVEL 01

Sign-Up: 01/06/06

Posts: 4

great post...but unfortunately i'm still can't understand. I am creating standalone shooting game. So, I want to save the game level while i playing-->>how is the code?
If i want to load the game that I saved before-->>how is the code? Can anyone explain step by step? Let me know how to do it. Please...really need help here. Please.


None

ELFERRETO

Reply To Post Reply & Quote

Posted at: 1/22/06 09:27 PM

ELFERRETO NEUTRAL LEVEL 12

Sign-Up: 12/03/04

Posts: 381

Wow devnish, i have never seen anyone do as much hard work as you, thankyou soo much for your help [ all of your posts have made me smarter! ] i am asking now if i can use your save / load code in my next game?


Shouting

nbstudios

Reply To Post Reply & Quote

Posted at: 1/23/06 10:58 AM

nbstudios NEUTRAL LEVEL 05

Sign-Up: 08/20/04

Posts: 8

Save button:
on (press){
savefile.data.score=_root.score;
savefile.data.level=_root.level;
savefile.flush();
}
Load Button
on (press){
var savefile = SharedObject.getLocal("Savegame");
if(savefile.data.score==undefined){
_root.score=0;
}else{
_root.score=savefile.data.score;
}
}
----The tip----
DO NOT USE THE TEST MOVIE OPTION!!!!!
INSTEAD: LOCATE THE SWF FILE AND JUST OPEN IT!!!


None

ELFERRETO

Reply To Post Reply & Quote

Posted at: 1/23/06 08:03 PM

ELFERRETO NEUTRAL LEVEL 12

Sign-Up: 12/03/04

Posts: 381

wow, favorites > add to favorites


None

liaaaam

Reply To Post Reply & Quote

Posted at: 3/4/06 02:03 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 3/4/06 02:00 PM, rainigul wrote: In "your game name", is your game name actually supposed to be swapped? Or is that the correct, total code?

You can swap it to whatever you want, but it has to be unique.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 3/4/06 03:12 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

So, I've wrote a basic save game class - which will basically let you save/load data with ease (you can also do such things as check all the saved information (only if it was saved using the class though) and.. stuff like that.

Class structure:

var name:SaveGame = new SaveGame("saveFileName");

Methods:

name.saveData("_y", 275); //sets _y to 275
trace(name.loadData("_y")); //trace 275
trace(name.saveData("_y", 100)); //trace false - the saveData method will only allow you to save a unique variable
name.resaveData("_y", 100) //sets already existing variable _y to 100
trace(name.dataExists("_y")) //trace true because there is an existing var called _y
trace(name.savedData()); //trace all existing variables in order of when they were originally saved
name.clearData(true); //Clears all saved data - Boolean needed to make sure you're meaning to clear the saved data and aren't just an idiot
trace(name.sizeOf()); //traces size of the flash cookie in bytes.

Enjoy.


None

Rustygames

Reply To Post Reply & Quote

Posted at: 3/4/06 04:10 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

nice work liam

- Matt, Rustyarcade.com


None

liaaaam

Reply To Post Reply & Quote

Posted at: 3/4/06 04:57 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 3/4/06 04:10 PM, Ninja-chicken wrote: nice work liam

*blush*

Lol thanks, I've been meaning to make a save/load class for ages - turns out it only took me 20 minutes =\ I didn't have any problems or anything, most disappointing.

p.s. I just watched Nanny McPhee and it really is shite.

None

llxll-Dylan-llxll

Reply To Post Reply & Quote

Posted at: 3/4/06 07:00 PM

llxll-Dylan-llxll LIGHT LEVEL 08

Sign-Up: 11/21/05

Posts: 91

Ok Im in need of help. I made a forum with no responses =( Here is my post maybe you can help. (im too lazy to edit it =) )

Im in need of help. I looked through Denvish's forum but I am bewildered. I am making a (somewhat) game and want it to be able to save and load all of frame 2 (well mainly just the inputted text), so when poeple use it again they can continue off of it. The game is located here: http://media.putfile.com/studyguide001 Also if anyone knows a better place to host files please point one out.


None

FFKing

Reply To Post Reply & Quote

Posted at: 3/30/06 01:55 PM

FFKing EVIL LEVEL 06

Sign-Up: 12/13/03

Posts: 358

Hi.
I'm using this save and load code, and all works well when i am playing the swf file.
but when i upload it and play it (embedded into a webpage) the save + load function doesnt seem to work.
Not sure if its a problem or whether its me being a dumbass.


None

authorblues

Reply To Post Reply & Quote

Posted at: 3/30/06 02:00 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 3/4/06 03:12 PM, -liam- wrote: So, I've wrote a basic save game class

you did that with arrays. did you think to do it with objects?
wouldve made all the load functions simpler, i think...

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 3/30/06 02:14 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 3/30/06 02:00 PM, authorblues wrote: you did that with arrays. did you think to do it with objects?
wouldve made all the load functions simpler, i think...

Hmm, that's a good idea I guess.. I can't be bothered now though xD


Angry

<deleted>

Reply To Post Reply & Quote

Posted at: 6/13/06 02:50 PM

it either didnt work or my copy of flash is fucked up.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/13/06 03:26 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 6/13/06 02:50 PM, Allen1288 wrote: it either didnt work or my copy of flash is fucked up.

I'm willing to bet you did it wrong. I'd put a lot of money on that.


None

icarus

Reply To Post Reply & Quote

Posted at: 7/14/06 02:20 AM

icarus EVIL LEVEL 12

Sign-Up: 01/10/05

Posts: 712

I was getting really frustrated with this, and i think many people have had the same problem-
make sure you use a button not a movieclip.

I hope that helps people, its a really simple thing but this code just wasn't working with a movieclip.

-icarus


Angry

Spam-Bomb

Reply To Post Reply & Quote

Posted at: 7/31/06 03:54 PM

Spam-Bomb NEUTRAL LEVEL 04

Sign-Up: 07/29/06

Posts: 174

it doesnt work


None

Thomas

Reply To Post Reply & Quote

Posted at: 4/9/07 10:29 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

Ok sorry for the big bump(and my ignorance for not reading the entire thread...it may answer my question somewhere...)

So my question is about saving into a new file,or something along those lines.

Say instead of saving the content into a temporary folder somewhere in the hard drive,is it possible to have a button(or automatic save) that will put the content of the Flash(Strings,Variables,etc)into a new file on a server so the content won't be lost if the owner accidentally deletes the cookies and loses their save files?

I ask because there could be a possibility of a Flash website with a log-in and passwords and such,but it would require to be saved elsewhere.

I'm not sure if this would require MySQL or not,just a question

All times are Eastern Standard Time (GMT -5) | Current Time: 04:29 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!