Space Realese

Well see i am making a new game(Took forever)

But see i noticed i can hold in Space bar and the counter will keep going up here si the code.

onClipEvent (enterFrame) {
    if (Key.isDown(Key.SPACE)) {
        _root.pu += 1;
    }
}

But i wouold want it to only go up when the SPACE bar is realesed

But how(Stumpued just like him:chinaman: )
Plesase help.

quick test …

onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
ok = true;
} else {
if (ok) k++;
ok = false;
}
trace(k);
}

like that?

or a shorter method


onClipEvent(enterFrame){
	if (s-(s=Key.isDown(Key.SPACE))>0) _root.pu++;
}

sorry kax, couldnt resist :wink:

Originally posted by senocular
sorry kax, couldn’t resist :wink:

it’s ok =). i love being belittled by you :wink: :stuck_out_tongue:

onClipEvent(enterFrame){
if (s-(s=Key.isDown(Key.SPACE))>0) _root.pu++;
}

I will test these both

onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
ok = true;
} else {
if (ok) k++;
ok = false;
}
trace(k);
}

*Originally posted by senocular *


onClipEvent(enterFrame){
	if (s-(s=Key.isDown(Key.SPACE))>0) _root.pu++;
}

that’s an interesting bit… do you mind explaining it?.. i just cant get it :beam:

Sorry Kax but i like senocular
better he is my best frined.

I also killled his cat

Originally posted by Bulldog_Flash
**Sorry Kax but i like senocular
better he is my best friend.

I also killled his cat**

i don’t care … he’s gonna marry me :beam: :stuck_out_tongue:

*Originally posted by ahmed *
**that’s an interesting bit… do you mind explaining it?.. i just cant get it :beam: **

:wink:

s is the variable the Key.isDown(Key.SPACE) is saved to, this happens every frame :slight_smile: Obviously. This happens in the if statement… again, fairly apparent. When it happens is after the first “s-” so if Key.isDown(Key.SPACE) is not the same at that point in time, that s in hte “s-” still holds the value of the previous frame - this value being either true or false, which numerically is either 1 (true) or 0 (false). And since the first s is not the current s, we are subtracting the values of Key.isDown(Key.SPACE) for this frame and the previous frame where it was last set: Last frame Space is down minus current frame space is down. Since we want to know when the space bar is released, we want the previous frame to be true and the current frame to be false or true minus false. That is the same as 1-0 which is 1 which is greater than 0. If both are true, you get 1-1 which is 0 and not >0. Both false, 0-0, or 0 and not >0. And with 0-1 you get -1 which is also, not >0 (-1 is in the case of just pressing the space bar). So in the end the only thing greater than 0 is the releasing of space. You could also say ==1, but the > sign is one character and == is 2 SAVED TYPING! :wink:

:beam:

:beam:
i get it now, interesting… =)

Kax neve he wil never marry you.

::Goes on his bed and starts to cry::

:-\

for the sake of the antispam wave [size=1]which i totally agree with[/size] … we should just leave this subject :wink: =)

anyway… we both know that he’s gonna marry me :stuck_out_tongue:

Yeah i think we should.
Bas tard.

But yeah since sen explined his why dont you explain your please.