# Score variable link with levels?

**URL:** <https://forum.kirupa.com/t/score-variable-link-with-levels/260273>\
**Category:** Uncategorized\
**Created:** [May 14, 2008, 1:50am UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273 "2008-05-14T01:50:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amymation](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@Amymation](https://forum.kirupa.com/u/Amymation)\
**Post date:** [May 14, 2008, 1:50am UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273/1 "2008-05-14T01:50:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 14, 2008, 2:12am UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273/2 "2008-05-14T02:12:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lou](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Lou](https://forum.kirupa.com/u/Lou)\
**Post date:** [May 14, 2008, 2:20am UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273/3 "2008-05-14T02:20:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bluemagica](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bluemagica](https://forum.kirupa.com/u/bluemagica)\
**Post date:** [May 14, 2008, 4:55am UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273/4 "2008-05-14T04:55:49Z")

</div>

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:-

```auto

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.

---

<div class="post-metadata">

**Author:** ![neilmmm](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@neilmmm](https://forum.kirupa.com/u/neilmmm)\
**Post date:** [May 15, 2008, 9:48pm UTC](https://forum.kirupa.com/t/score-variable-link-with-levels/260273/5 "2008-05-15T21:48:55Z")

</div>

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)

```auto

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

```

hope this helps
