# Stop script

**URL:** <https://forum.kirupa.com/t/stop-script/62917>\
**Category:** Uncategorized\
**Created:** [September 1, 2004, 4:41pm UTC](https://forum.kirupa.com/t/stop-script/62917 "2004-09-01T16:41:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [September 1, 2004, 4:41pm UTC](https://forum.kirupa.com/t/stop-script/62917/1 "2004-09-01T16:41:14Z")

</div>

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?

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 4:44pm UTC](https://forum.kirupa.com/t/stop-script/62917/2 "2004-09-01T16:44:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 4:46pm UTC](https://forum.kirupa.com/t/stop-script/62917/3 "2004-09-01T16:46:27Z")

</div>

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{

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 5:08pm UTC](https://forum.kirupa.com/t/stop-script/62917/4 "2004-09-01T17:08:27Z")

</div>

I think you are missing a {

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 6:45pm UTC](https://forum.kirupa.com/t/stop-script/62917/5 "2004-09-01T18:45:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 6:50pm UTC](https://forum.kirupa.com/t/stop-script/62917/6 "2004-09-01T18:50:58Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 9:43pm UTC](https://forum.kirupa.com/t/stop-script/62917/7 "2004-09-01T21:43:27Z")

</div>

> [@shuga](#):
>
> this is what i have now and it works … sorta … well it doesn’t throw up an error
> 
> ```auto
> 
> 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();

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 9:58pm UTC](https://forum.kirupa.com/t/stop-script/62917/8 "2004-09-01T21:58:54Z")

</div>

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

:hr:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 11:44pm UTC](https://forum.kirupa.com/t/stop-script/62917/9 "2004-09-01T23:44:15Z")

</div>

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 🙂

thank you again

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 11:51pm UTC](https://forum.kirupa.com/t/stop-script/62917/10 "2004-09-01T23:51:20Z")

</div>

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

iow:

```auto

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

```

is equivalent to

```auto

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

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

```

:hr:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2004, 12:52am UTC](https://forum.kirupa.com/t/stop-script/62917/11 "2004-09-02T00:52:20Z")

</div>

> [@lunatic](#):
>
> if I understand it correctly the ‘if’ is implied (due to the other symbols), the ? stands for ‘then’ and the ‘:’ stands for ‘else’.
> 
> iow:
> 
> ```auto
> 
> i == undefined ? i=0 : i++;
> i == 3 ? stop() : play();
> 
> ```
> 
> is equivalent to
> 
> ```auto
> 
> if(i == undefined){
> i=0;
> }
> else {
> i++;
> }
> 
> if(i == 3){
> stop();
> }
> else {
> play();
> }
> 
> ```
> 
> :hr:

yes exactly

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2004, 1:03am UTC](https://forum.kirupa.com/t/stop-script/62917/12 "2004-09-02T01:03:36Z")

</div>

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

:beam:
