The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.

ForumsProgramming ForumKeeping stats/variables

11 5485
Xinito
offline
Xinito
109 posts
Nomad

I'm trying to create a RPG Game in AS2 and I have made a "shop".
For example I got 50 exp and I enter the shop it still says 50 exp in my Variable, this is good but.... When i'm done in my store and want to go to the world/zone I lost my stats/variables it's 0 agian. This is what I got:

To enter the shop I got:
onClipEvent (enterFrame) {
if (_root.Character.hitTest(this))
{
_root.VCam.gotoAndPlay(2);
_root.gotoAndPlay(2);
}

}
to leave the shop I got:
onClipEvent (enterFrame) {
if (_root.Character.hitTest(this))
{
_root.prevFrame()
//or _root.gotoAndPlay(1)
_root.VCam.prevFrame()
//or _root.VCam.gotoAndPlay(1)
}
}

Is it possible that I keep my variables numbers when I go back to frame 1(world) agian, and how??

  • 11 Replies
Xinito
offline
Xinito
109 posts
Nomad

Anyone??

Hectichermit
offline
Hectichermit
1,828 posts
Bard

create a layer with one key frame that is on every frame that you need that variable on, just add frames, not key frames then put your variables in that key frame. I don't know much about as2 but if it were as3 you could just create a document class and have all your variables in there.

Xinito
offline
Xinito
109 posts
Nomad

Got it, thanks

Xinito
offline
Xinito
109 posts
Nomad

Hmm this dont seems to be working :S, I made a new layer and frames and on the keyframe I putted:

speed = 5;
experience = 0;
playerlevel = 1;
health = 100;

but it still wont work

master565
offline
master565
4,104 posts
Nomad

Store the values in an external file.

Xinito
offline
Xinito
109 posts
Nomad

How??

arobegamr
offline
arobegamr
130 posts
Nomad

Are you using onClipEvent(load) to define your exp variable?

My guess is that on you are defining the variable on your player, and every time flash has to load the player, it calls back the onClipEvent, and sets the variable to 0. Don't define variables on your player movie clip, or it will be reset every time, and if the movie clip is ever removed, the variables will be lost. And again, I strongly recommend that you do not use onClipEvents at all. They are very tedius.

Also, if you are defining variables on the main stage, ex. player.exp = 0, a similar problem happens, and every time that frame is loaded, the variable is set to zero. Here's one way to fix it:

When defining the exp variable, check if it has already been defined:
if(exp == undefined){
exp = 0;
}

I recommend attaching the variables to the main stage rather than the player movie clip.

PixelSmash
offline
PixelSmash
566 posts
Nomad

Quick guess? When you do the prevFrame, the code for that frame is executed again... meaning the values are overwritten with their initial value

Xinito
offline
Xinito
109 posts
Nomad

Thanks for the comments guys trying AS3 and forgetting about AS2 heared everywhere AS3 is better

Hectichermit
offline
Hectichermit
1,828 posts
Bard

normally you gotta use a document class/external classes, some as3 books advocate not programming on the timeline

Xinito
offline
Xinito
109 posts
Nomad

This thread can be locked, thanks for the answers and i'll stop using AS2 and start learning AS3

Showing 1-11 of 11