# Var counter thingy - easy peasy (no really)

**URL:** <https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737>\
**Category:** Uncategorized\
**Created:** [February 17, 2003, 3:59pm UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737 "2003-02-17T15:59:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericinho](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@ericinho](https://forum.kirupa.com/u/ericinho)\
**Post date:** [February 17, 2003, 3:59pm UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/1 "2003-02-17T15:59:10Z")

</div>

I have a SWF that loops on the main.

now I want that after 4 or 5 times of looping it does an action.

I know that with Var I can count and then with a little action I can instruct Flash that when a var value is reached it executes an action.

But how again do I do that?

(it was something with varofsumthing = “+1”

if varofsumnthing == “5”  
gotoandplay(whatever)

hope you lot can help me out 🙂

---

<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:** [February 17, 2003, 6:31pm UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/2 "2003-02-17T18:31:46Z")

</div>

```php

if(counterVariable++ == 5){
  // Do something.
}

```

Just make sure you initialize counterVariable first. 🙂

-Al

---

<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:** [February 17, 2003, 9:47pm UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/3 "2003-02-17T21:47:14Z")

</div>

so my varofsumthing = “+1” was actually correct???

wow! 😉

---

<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:** [February 17, 2003, 10:10pm UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/4 "2003-02-17T22:10:27Z")

</div>

in one frame I have this to either continue to play if the varcount did not reach 3 or to stop if it did…

```php
if (this.countvar++ == 3) {
this.gotoAndStop(347);
}
else { 
this.gotoAndPlay(347);
}

```

and this action to set the var with each loop with an increase of 1

```php
this.countvar +=1;

```

but, as you guessed… It don’t work 🙂

---

<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:** [February 18, 2003, 2:35am UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/5 "2003-02-18T02:35:42Z")

</div>

variable++ is the same as variable += 1

So in my code, the variable is incremented in the IF statement.

Now that I have a better idea of what you want, try this in frame 347:

```php

if (this.countvar == 3) {
  this.stop();
} else { 
  this.gotoAndPlay(346);
}

```

You have to go to the previous frame. Going to the same frame won’t work (I think). And of course, make sure you have this in a frame before 346:

```php

this.countvar = 0;

```

And you need to increment your counter somewhere with your

```php

this.countvar += 1;

```

or

```php

this.countvar++;

```

-Al

---

<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:** [February 18, 2003, 9:12am UTC](https://forum.kirupa.com/t/var-counter-thingy-easy-peasy-no-really/13737/6 "2003-02-18T09:12:28Z")

</div>

works fine!

thanks mate!
