I need help with a script i made

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:


    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;
        }
    }


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

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

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.

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

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 :wink:

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?

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.

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…)

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

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” :smiley:

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 =))

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.

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?

:h:

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

well why didn’t ya just say that:)

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