# I need help with a script i made

**URL:** <https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179>\
**Category:** Uncategorized\
**Created:** [March 24, 2006, 11:56am UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179 "2006-03-24T11:56:36Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 24, 2006, 11:56am UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/1 "2006-03-24T11:56:36Z")

</div>

i made a script thet if i press right it will go in speed=5 and if i press twice it will go in speed =20 can someone explain me why if im pressing the first time it wont go in speed=20?  
here is the code:  
Code:

```auto

    if (Key.isDown(Key.RIGHT) ) {
        this._xscale=100;
        this._x+=speed;
        f=1;
    } else {
        if (f==1) {
            speed=20;
        } else {
            speed=5;
        }
        ddd--;
        if (ddd<=0) {
            ddd=0;
            f=0;
        }
        if (f==0) {
            ddd=3;
        }
    }

```

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 25, 2006, 6:42pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/2 "2006-03-25T18:42:01Z")

</div>

i mean how is the “else” working, beacuse else doing something if the commend returns false

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 26, 2006, 8:18pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/3 "2006-03-26T20:18:18Z")

</div>

here is the file:  
[http://www.kirupa.com/forum/attachment.php?attachmentid=34636&stc=1&d=1143404278](http://www.kirupa.com/forum/attachment.php?attachmentid=34636&stc=1&d=1143404278)

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 26, 2006, 8:32pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/4 "2006-03-26T20:32:19Z")

</div>

if you press your RIGHT key, f will be changed to 1, and flash will enter to else statement all times you are not pressing this key. So, before start moving first time your clip, “else” have already returned the speed. Each time you move your clip, when key.RIGHT isnt down itll change and reload your speed. So, I think you may change f to 0 again, where it has been passed as true(1) ( if (f==1) {speed=20; f=0;} ), because youre loosing your “second press effect” after first game.

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 26, 2006, 8:50pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/5 "2006-03-26T20:50:22Z")

</div>

oh so when im letting go right, it have a few milisecounds of f=1 am i right?

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 26, 2006, 9:28pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/6 "2006-03-26T21:28:42Z")

</div>

Yes, when you press it first time, you have the time before ddd become again " \<=0 " to get the speed at 20. If you wait too much, f is changed again to 0 and else statement returns speed at 5. You have only access to high speed when ddd timer hasnt passed the restriction level, thats it 😉

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 27, 2006, 1:02pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/7 "2006-03-27T13:02:36Z")

</div>

i dont get it, else shouldent executed statments only if your letting the key?if the statment is in else how can it be thet when im pressing it execute the statment?

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 27, 2006, 7:18pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/8 "2006-03-27T19:18:58Z")

</div>

To execute it, just inside if statement. flash will enter to “if” if the condition is true, when you press RIGHT.key. Else it will execute else statement thats all. If ypu have the code in a loop function (onEnterFrame) the else statement will be always running before press RIGHT key.

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 27, 2006, 8:12pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/9 "2006-03-27T20:12:47Z")

</div>

oh so when i write the “if” statment it doesnt metter where it is?  
it will allways execute by the data i give it?  
(sorry for the grammer…)

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 28, 2006, 8:56am UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/10 "2006-03-28T08:56:27Z")

</div>

but how can i execute an “if” statment wich in else by pressing right? can u explain it to me?

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 28, 2006, 10:27pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/11 "2006-03-28T22:27:04Z")

</div>

The “key.isDown” method returns true or false (1 or 0) depending if its pressed or not. I think it is inside a loop function, so, It will continuisly verify the condition. If key.isDown is true, enter to if statement, else, enter to “else” 😃

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 29, 2006, 1:20pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/12 "2006-03-29T13:20:29Z")

</div>

yes but how is it thet when i press right f=1 and when “else” and im pressing right im executing the statment  
how can it be?  
(sorry for the headeaks i give you =))

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 29, 2006, 8:34pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/13 "2006-03-29T20:34:46Z")

</div>

Theres only “if” or “else” at a same time. If key is pressed turn f to 1, else, it will be in “else” statement. Even if youre inside else statement, if you press RIGHT key it will jump to “if” statement and turn f to 1, if it has been already changed or not, It doesnt matter.

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [March 29, 2006, 8:57pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/14 "2006-03-29T20:57:06Z")

</div>

oh so the “if” statment in “else” doesnt belong if its in the else? it like telling the flash thet when you are living the key commend an if statment and when you press you tell the flash thet the if is true?

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 29, 2006, 8:58pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/15 "2006-03-29T20:58:44Z")

</div>

:h:

---

<div class="post-metadata">

**Author:** ![goto](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@goto](https://forum.kirupa.com/u/goto)\
**Post date:** [March 30, 2006, 10:50pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/16 "2006-03-30T22:50:32Z")

</div>

Ummmm :crying: , flash evaluates the condition inside “if”, I mean the key.isDown condition, it returns true or false, depending if the key is down or not, so, if its true it will enter inside “if”. else, it will enter inside “else” because it suppose flash didnt eneter inside if because the condition wasnt true

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 30, 2006, 10:51pm UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/17 "2006-03-30T22:51:44Z")

</div>

well why didn’t ya just say that:)

---

<div class="post-metadata">

**Author:** ![flamer](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@flamer](https://forum.kirupa.com/u/flamer)\
**Post date:** [April 2, 2006, 5:18am UTC](https://forum.kirupa.com/t/i-need-help-with-a-script-i-made/183179/18 "2006-04-02T05:18:05Z")

</div>

sorry im such pain in the \*\*\*  
but i dont get it how the if in else workes when im pressing the key
