Score Problems

I was just reading a tutorial (http://www.flashkit.com/tutorials/Games/How_to_m-MODVDO-969/index.php) and was wondering how to do this:

I already have a dynamic text box with the instance name “score” and the variable “score”. I want to go to scene 4 when the score reaches 10,000. But the tutorial only explains how to do it when a button is pressed down. How do I get it to work when my “score” reaches 10,000?

Any suggestions?

:h:

Remove the instance name for the textfield and place thiis code on the timeline:

this.onEnterFrame = function(){
if(this.score==10000){
this.gotoAndPlay("Scene 4","1")
}
}

ahh good but… (yes i know theres always a catch)

My game never reaches 10000 exactly. How can i make it so if it reaches 10,000 OR over that it goes to scene 4?

thx :slight_smile:

this.onEnterFrame = function(){
        if(this.score>=10000){
                this.gotoAndPlay("Scene 4","1")
        }
}

it still doesnt work! wut is wrong?

I dont know, but scenes sometimes can behave weird

and i cant post my game because the scene is too big!

You’re mixing things up… use a different instance name for the text field, something like score_txt. :stuck_out_tongue:

And there’s no need for an [font=courier new]onEnterFrame[/font] handler, you’re wasting resources; use the [font=courier new]Object.watch()[/font] method instead.

function checkScore(prop, vold, vnew) {
	if (vnew>=10000) {
		this.unwatch("score");
		this.gotoAndPlay("Scene 4", 1);
	}
	return vnew;
}
this.watch("score", checkScore);

Nice kax, never thought of using the watch method for that. Is that good for memory usage precaution?

Yeah (at least for me), I use it all the time for games and stuff. :slight_smile:

Do you know where i can find more info on memory usage in actionscript?

Uhmm… no, I don’t remember any. I’ll let you know if I find (or remember) anything. :wink:

Thanks :thumb:

No problem. :beam: