PDA

View Full Version : saving code question



leonthelion
December 1st, 2007, 02:16 AM
Heres my code:


function savegame(){
myLSO = SharedObject.getLocal("Xin_Chapter1");
if(myLSO.data.myObj == undefined){ // No object exists
trace("Saved Game");
}
else{
trace("Overwrote Saved Game");
}
myObj = {};
myObj.objArray = new Array();
myObj.objArray[0] = hp;
myObj.objArray[1] = mp;
myObj.objArray[2] = maxhp;
myObj.objArray[3] = maxmp;
myObj.objArray[4] = atk;
myObj.objArray[5] = def;
myObj.objArray[6] = sp;
myObj.objArray[7] = maxsp;
myObj.objArray[8] = xp;
myObj.objArray[9] = maxxp;
myObj.objArray[10] = maxatk

myLSO.data.myObj = myObj;
}

function loadgame(){
myLSO = SharedObject.getLocal("Xin_Chapter1");
if(myLSO.data.myObj == undefined){ // No object exists
trace("No Saved Game");
}
else{
trace("Loaded Game");
hp = myLSO.data.myObj.objArray[0];
mp = myLSO.data.myObj.objArray[1];
maxhp = myLSO.data.myObj.objArray[2];
maxmp = myLSO.data.myObj.objArray[3];
atk = myLSO.data.myObj.objArray[4];
def = myLSO.data.myObj.objArray[5];
sp = myLSO.data.myObj.objArray[6];
maxsp = myLSO.data.myObj.objArray[7];
xp = myLSO.data.myObj.objArray[8];
maxxp= myLSO.data.myObj.objArray[9];
maxatk=myLSO.data.myObj.objArray[10];
}
}

My question is I used to have all the variables (atk, def, hp, sp, etc.) as _root. type variables, I have changed them to _global. variables so I could have a movieclip with the dynamic text inside it. Okay so the real question is: would I have to change any of the code in any of the functions because of this? Thanks

OFF TOPIC:
would it be possible to do this?
1. make dynamic text
2. put the variable health in the variable box
3. put this code on the frame:_root.health.text=_global.hp
Would it be possible to do that? Thanks again

marvolo_cullen
December 2nd, 2007, 02:37 PM
try
_root.health.text = "" += _global.hp

or

_root.health.text = "" + _globa.hp

im not sure offhand which will work but im 99% sure one of them will work

wait i just reread your question again and i found your error
put health in the instance name box and _root.hp in the variable box... and that should do it!

leonthelion
December 2nd, 2007, 03:17 PM
I tried the codes for the offtopic but none of them worked :( Anyway got anything for the save part?
I have another question, can you save functions with the code?