Score variable link with levels?

Hi,
I’m having a problem with my game. Theres a score system that works fine but I have many levels now and I’ve noticed that at the begining of each level the score resets. I know it has something to do with the timeline code;
_root.score = 0;

I know I need to adjust it but I don’t know how?

I’ll need the score from previous level. And also i’ll need the same for the lives
_root.lives = 10;

please reply! xx

Well, usually variables stay the same on each frame unless you change them. Where you put the the _root.score = 0 code? My advice is to put that on the play button so it doesn’t interfere with the game.

You’ll need to post more of your code so we can see exactly what is going on. It looks like _root.score = 0; is being set on every frame or inside of a function somewhere but It should only be set once.

In this scenarios i prefer using a global variable , _global.score=0. But in your case, you must be using a onLoad or such to execute some initialisations and setting the _root.score=0; and thats why the problem arises!!! We, as others said, can’t really help much without looking at your code, but till you show us the code, try this:-

Wherever you have:-
_root.score=0;

Replace it with:-


if(not(_root.score>=0))
  _root.score=0;

but i do suggest you use _global.score instead of _root.score for an increased scope of the variable.

i use 2 variables : score and levelScore

you increment score and incremnet levelScore but when levelScore is bigger than than x i go up a level and subtract from levelScore - the game player does not know levelScore exist

something like this (not tested)


function addScore(){
score+=scoreAmount;
score_txt.text=score;
levelScore+=scoreAmount;
if(levelScore>200){
level++;
levelScore-=200;
}
}

hope this helps