Stop script

i’m trying to figure out how to create a script that will perform a stop(); after the frame has been hit 3 times

so i think i need to set a variable and add 1 to it each time the frame is hit until it gets to 3 and then when it hits 3 stop();

so would it look like this?


i=0
onEnterFrame{
if (i>=3){
stop();
}else{
i+=1;
}
}

Looks good to me. What happens when you try it? :beam:

This is the error it produces when I put the code on the frame where I want the animation to stop

Symbol=image anim, Layer=stop script, Frame=465: Line 2: ‘;’ expected
onEnterFrame{

I think you are missing a {


i=0
onEnterFrame{
if (i>=3){
stop();
}else{
i+=1;
}
**}** //<-- add this to the bottom

i see no difference between the code you posted and the code i posted except you bolded one of the curly brackets and told me to put it at the bottom … but it’s already there … i’m confused

this is what i have now and it works … sorta … well it doesn’t throw up an error


i = 0;
onEnterFrame = function () {
	if (i>=3) {
		stop();
	} else {
		i += 1;
	}
};

what it does do is stop after it’s gone through the animation 1.25 times … basically it goes through it once and then starts going through again and stops … not even on the frame where the action is.

it’s like the action starts and then every frame it increments ‘i’ and stops after 3 frames b/c i = 3

if your animation is looping on its own, just type this in the first frame (of the animation)
i == undefined ? i=0 : i++;
i == 3 ? stop() : play();

EDIT/
if you want it to stop in the last frame, type this in the last frame
i == undefined ? i=0 : i++;
i == 2 ? stop() : play();

:stuck_out_tongue: oops, sorry - I meant to add another bracket at the end but I was in a rush. Did stringy’s code work?

:hr:

it did work … thank you so much stringy

that code looks really condensed … if you have a free moment, an explanation of what you typed would be so helpful in my studies :slight_smile:

thank you again

if I understand it correctly the ‘if’ is implied (due to the other symbols), the ? stands for ‘then’ and the ‘:’ stands for ‘else’.

iow:


i == undefined ? i=0 : i++;
i == 3 ? stop() : play();

is equivalent to


if(i == undefined){
  i=0;
}
else {
  i++;
}

if(i == 3){
  stop();
}
else {
   play();
}

:hr:

yes exactly

[homer voice] WOO HOO!! [/homer voice]

:beam: