PDA

View Full Version : Help on save game??!!



TrapHole_2032
July 30th, 2005, 08:02 AM
Heeyy, I was wondering how you could save games like in RPGs(i.e. Pokemon), but I couldn't use shared objects or cookies because not everyone uses the same computer to play the game, what if they change computers, how could you load then??

Thx

Dauntless
July 30th, 2005, 08:47 AM
Store evrything in a database. F.e. MySQL.

Joppe
July 30th, 2005, 09:42 AM
How do you do that? Store everything in a mysql database?

Dauntless
July 30th, 2005, 09:53 AM
Use the LoadVars object to send your data to a php file. You can use these (http://www.kirupa.com/web/index.htm) tutorials to learn how to put php data into an mysql database.

.:.:Lui:.:.
August 2nd, 2005, 12:09 AM
how bout not php? how bout something thats not too complicated?
<-Quote from Skye, CEO of XgenStudios.Com->
Hello! Sorry I took so long to get around to this question.

The answer lies in the new sharedObject data type introduced in Flash MX. You must use Flash MX for this tecnique.

I prefer to split my Saving and Loading code into functions in order to keep things neat and organized.

Place this code in the first frame:



function saveGame(){ myLSO = SharedObject.getLocal("uniqueName"); if(myLSO.data.myObj == undefined){ // No object exists trace("Saved Game"); } else{ trace("Overwrote Saved Game"); } myObj = {}; myObj.objArray = new Array(); myObj.objArray[0] = lives; myObj.objArray[1] = score; myObj.objArray[2] = apples; myLSO.data.myObj = myObj; } function loadGame(){ myLSO = SharedObject.getLocal("uniqueName"); if(myLSO.data.myObj == undefined){ // No object exists trace("No Saved Game"); } else{ trace("Loaded Game"); lives = myLSO.data.myObj.objArray[0]; score = myLSO.data.myObj.objArray[1]; apples = myLSO.data.myObj.objArray[2]; } }




That's it!

Now you can just call the save and load functions like this:

saveGame(); // Code to save current state
loadGame(); // Code to load current state


There are a few things you want to change in the code itself to customize it for your specific needs.

- Replace "uniqueName" with... yeah... a unique name
This will identify which object to save/load, so that you can have multiple objects stored on the users HDD.

- Change the variables. 'Lives' and 'Score' are probably different than the variable names you want to save. You should include all variables which are important to the game state, and you can include more than three by using more array locations.

EG.
myObj.objArray[3] = oranges;
myObj.objArray[3] = coconuts;
etc....

Templarian
August 2nd, 2005, 01:22 AM
He just said in his first post no shared objects. I dont use them but im pretty sure thats what you just explained above.

TrapHole_2032
August 4th, 2005, 08:26 PM
Ehem... :scream:

NO shared objects or cookies, thank you.


Err...

I was wondering if you could save the php save file into a website, not a database server?
Like, save to "www.someDomain.com/savegame/save01.php" or something like that..

dinner dog
August 4th, 2005, 09:34 PM
you could save to a file but you will end up with a big file if you have a lot of users. you could use a php file to hold the passwords and data for each user (i.e. seperate file each user). this would allow for you to save and open using a php function and if you structure it right no one outside your server will be able to see the passwords in the php file.

Templarian
August 4th, 2005, 11:17 PM
off topic
Tip when you save your variables make sure they are saved in a string such as var1,var2,var3... This is the best way i have found to save variables such as items that you have and so on.

jerez_z
August 5th, 2005, 12:03 AM
I have done some experimentation using php and no database. You'll need to make sure you have writeable files and things like that but it is definatley possible.

Dauntless
August 5th, 2005, 01:36 AM
off topic
Tip when you save your variables make sure they are saved in a string such as var1,var2,var3... This is the best way i have found to save variables such as items that you have and so on.
IMO, XML is better ! But that's probably because i really like working with xml in flash. You can save evrything in xml format and just load the xml out of the file and print it to flash. That way your data has a good structure in stead of just 1 big long string...

Templarian
August 5th, 2005, 01:45 AM
Yea, for what hes doing he could use an XML file. It would be easer to check if its saving right later on.

off topic____
Yea, dauntless i work with very large files. My map file contains like 1000 variables that dont count the actual map ones themselves. and each tile looks like "M1-1=1,hello,2,3,4,5" So in the end to get my save file to work i will be saving a fare amount of data to a file.

tofu
August 5th, 2005, 05:03 AM
IMO, XML is better ! But that's probably because i really like working with xml in flash. You can save evrything in xml format and just load the xml out of the file and print it to flash. That way your data has a good structure in stead of just 1 big long string...I was under the impression you couldn't simply save XML to a file? Loading XML is simple, but I haven't figured out how to save it yet. The few tutorials I've read require some server-side script to recieve files. Have you got a way to do it? It would help me greatly if you could elaborate.

Dauntless
August 5th, 2005, 06:53 AM
I was under the impression you couldn't simply save XML to a file? Loading XML is simple, but I haven't figured out how to save it yet. The few tutorials I've read require some server-side script to recieve files. Have you got a way to do it? It would help me greatly if you could elaborate.That's true... You can't just save a file with flash. You have to post them to a php/asp/perl/whatever (serverside script) file and you can save it there...

Lord Rahl
August 5th, 2005, 03:02 PM
Referring to .:.:Lui:.:. post (#5)

Would it be possible to save a frmae number and load to that frame when a game is loaded? And if so, how? Something like:
gotoAndStop(myObj.objArray[3]);
or something? Or would it have to be something long having to do something like myObj.objArray[3] = frame;
then some if(current frame blah blah) script?

TrapHole_2032
August 7th, 2005, 01:10 AM
Now I know!

Use LoadVars object and save it to a file!

I read the Flash help file over and over again and then I knew that the loadvars object is the most useful one.

First, make a new loadvars object :

save = new LoadVars();

And then if you want to save, just send the variables.

save.send(save01.php);

Load it!

save.load(save01.php);

Of course, I don't GUARANTEE it will work. :-/

ryguyspk
August 7th, 2005, 06:39 PM
I don't understand why you wouldn't use the shared object. Just put all your save stats into an array and store the array into the shared object.

I'm not sure how secure you want your game... the Shared Object does encrypt your file to a point, unlike if you were loading and saving from an XML file. If you used an XML file locally, a player would easily edit and give themselves more lives, score, items, etc.

I see what you would have it stored on the server-side though, especially for a multiplayer game. For example, you could store an XML on the server-side and Flash builds the XML save on the fly. That way, whatever variables you are saving are saved and loaded from the server, rather than locally. Even if a player sniffed out the XML file and opened it, they wouldn't be able to upload an edited version. (unless you FTP is wide opened, of course).

-Ryan

jerez_z
August 7th, 2005, 08:56 PM
If you use the Macromedia Flash Communication Server you can store your shared object on the server-side. Then it would be the best way to go.

LigerZX
August 21st, 2005, 05:09 AM
I too am looking for a solution to this, Theres this Java script thingo that game out with the 7.2 update. Is there no way to use that to save a file without any server based software?

On that note, is there no freely available software for flash to save files offline and without a server? Suppose your making an offline game? ANyone?

charmander
August 21st, 2005, 07:24 AM
could this file help?

it's one problem that it's work with flash 5 only..........you must publish it from flash 5

LigerZX
August 21st, 2005, 08:10 AM
Was thinking more of like an extension. Could one be written if I had enough knowledge about classes?

jerez_z
August 21st, 2005, 11:43 AM
for an offline game use the SharedObject.

As far as I know there isn't any way to save a game online without server-side software. Its not very hard to make either

LigerZX
August 22nd, 2005, 03:39 AM
Yeah but what if your making an application, eg a client listing stock program for offline use only and you want to save a listing of the client name and stock as an xml file or soemthing like that which can be used to transfer to another computer. As advanced as flash is there has to be some way around this.

maxp
August 27th, 2005, 02:48 AM
You could use passwords. So for each level, there is a password to play it.

TrapHole_2032
September 1st, 2005, 10:15 AM
You could use passwords. So for each level, there is a password to play it.
No you can't, passwords are easily given away.
Anyways, I'm makin' an RPG. You can't just use password for RPGs, you know.

Dauntless
September 1st, 2005, 01:03 PM
Sure you can... They would just be waaaaaaaaaaaaaaaaaaaaaay to long ;)

TrapHole_2032
September 2nd, 2005, 11:42 PM
Urgh, You don't know what I mean.
Did you read what I said :


Anyways, I'm makin' an RPG. You can't just use password for RPGs, you know.


RPGs use inventorys, for one thing.
People have different inventorys, right?
Understand?

Haven't you ever played an RPG?

So you cant use
passwords for levels.