If Statment in a Enter Frame

I have an If statment in a on(EnterFrame) in side the actions of a movie clip. For some reason it does not work. I have other if statments in on enter frames and they all work but this one jsut doesn’t.

I was told that a on(enterframe) continues to repeat the code while the frame head is over it so it should alwasy check the if statment until the conidtion comes true and moves the frame head. Is my logic not correct?

Here is the code

onClipEvent (enterFrame) {
	if(_root.life <= _root.dead) {
		gotoAndPlay("main", "gameover");
	}
}

It is for a shooting game. “life” starts at “100” and “dead” is “0”. When my “life” drops to “0” it will be less then or equal to “dead”. It should goto the fram label “gameover” which has a stop action and display some game stats. Any ideas

_root.gotoAndPlay… :sure:

_root, or any clip you want, of course, as long as the path is correct :slight_smile:

Ok i added the _root( which i would have never noticed)

onClipEvent(enterFrame) {
	if(_root.health <= _root.dead) {
		_root.gotoAndPlay("main", "gameover");
	}
}

And the paths are al right and stuff but when health reaches zerp it still won’t exicute the code. Could i e-mail u the FLA if your not to busy?

Try this:

onClipEvent(enterFrame) {
	if(_root.health <= _root.dead) {
		_root.gotoAndPlay("main", "gameover");
		trace ("Ya dead!");
	}
}

Does it trace anything? If it does, it’s probable that it’s not working because you’re gotoAndPlaying to a scene name. Try to use frame labels instead.

pom :phil:

By the way, I hope I can see the finished game some day :slight_smile:

are you using scenes? :!:

:slight_smile: its a common problem with using scenes in movieclips. In short, you cant use scenes in movieclips, only from the main timeline. Though you may have written that code from the maintimeline, its still being played in the scope of that movieclip, at which case the movieclip is trying to go to the label “main”

if you want to go to a frame in the main timeling from there, you should use a frame label and say

_root.gotoAndPlay(“frameLabel”)

Although Scenes are horrible, they really do need to fix some bugs with using them :-\

Ya it hit zero and it started to trace yets it still wouldn’t play the goto. I changed the goto to jsut a frame numbe and now it works. but i’m having some score issues. Here is a link for the game so far. No preloaders yet and it is 58k so it might taek a bit.
*edit ya sen i was trying to use scenes fir the first part and that was porbably the biggest probelm. now that i’m not it works fine.

http://www.sintax321.com/sgt/sgtgame.html

Ok i got the score working and a “play again” button. Ther is still a ton of detail i’m going to put in but thisis the bulk of it.

*edit oh ya and thanks for all your help you guys.(-:

http://www.sintax321.com/sgt/sgtgame.html

Cool game :cool:

You should make the dynamic text boxes unselectable… ya know… while your still working on it and all :slight_smile: