Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: score variable link with levels?

  1. #1

    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

  2. #2
    Jephz's Avatar
    106
    posts
    The Penguin n00b
    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.
    Don't you ever, ever, EVER call me a Noob. I mean it!

  3. #3
    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.

  4. #4
    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:-
    Code:
    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.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  5. #5
    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)
    Code:
    function addScore(){
    score+=scoreAmount;
    score_txt.text=score;
    levelScore+=scoreAmount;
    if(levelScore>200){
    level++;
    levelScore-=200;
    }
    }
    hope this helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012