Results 1 to 6 of 6

Thread: question about keeping score / defining a winner

  1. #1

    question about keeping score / defining a winner

    I've made a game where you click on different floating objects to get different point amounts. I have a dynamic text box that has a variable set to score and then when the user presses the floating objects it adds points to the score.

    That all works fine, but now I need an action so that
    when the score reaches 100 it proclaims you as the winner.

    Any suggestions?

  2. #2
    Guig0's Avatar
    1,502
    posts
    back from hell

    how about:

    Code:
    if (score>=100){
    	_root.gotoAndStop (#);
    }
    # = number of the frame with the message: You Win!


  3. #3
    Thanks for your help!

    Unfortunately I tried putting the code

    if (score>=100){
    _root.gotoAndStop (2);
    }

    on frame one of the movie (it's only 2 frames long) and when I rack up to 100 it still doesn't go on to frame 2. Any ideas as to why?

    They way I'm adding points is with an action attatched to a button that says

    on (release) {
    _root.score = _root.score +5;
    }

    is there something wrong with that?

  4. #4
    yeah, dont put it in the frame, put it in the button since that is being used to alter score:


    on (release) {
    _root.score = _root.score +5;
    if (score>=100){
    _root.gotoAndStop (2);
    }
    }

  5. #5
    Guig0's Avatar
    1,502
    posts
    back from hell
    sen is right.

    That happens cause the if condition in the frame doesnīt keep updating itself, it checks once (in the beggining) and the score is lower than 100, so it doesnīt do anything but when it reaches 100 the condition isnīt checking again.

    You can place it on the on (release), of the button, like sen told you to do, and every time the button is released the condiditons is checked again.


  6. #6
    if you want to do it by frame, you can be a 'good' mx programmer and use object.watch

    Code:
    onNewScore = function(){
    	if (this.score >= 100) this.gotoAndStop(2);
    	return arguments[2];
    }
    _root.watch("score", onNewScore);
    since you are 'watching' the score value in _root, you call watch from root and include "score" (variable to watch) and the function to be run whenever that variable changes, which in this case is onNewScore. onNewScore checks the score and sees if its over 100, and it it is, goes to frame 2. The return arguments[2]; just keeps the score from changing (since watch lets the onNewScore function change that value should it need to with a return argument, if you dont want to change it, just return arguments[2] which is the value it was changed to when this was called in the first place)

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