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?


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

[SIZE=3]#[/SIZE] = number of the frame with the message: You Win!

:slight_smile:

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?

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);
}
}

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.

:slight_smile:

if you want to do it by frame, you can be a ‘good’ mx programmer and use object.watch :slight_smile:


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)