problem with wait action?

Get help using Construct 2

Post » Thu Mar 26, 2015 2:46 pm

Image

this is the code i have.
basically what i want is to have a cooldown of 1 second on the attack (so the player cant keep bashing the button)
what happens is sometimes it works, sometimes it resets the "p_SwordAttackCooldown" variable immediately without waiting 1 second. any ideas????
Image
B
18
S
5
G
2
Posts: 60
Reputation: 1,575

Post » Thu Mar 26, 2015 3:53 pm

You could use the timer behavior instead of the wait action.

edit :
https://www.scirra.com/tutorials/56/how ... ait-action
If you haven't read it, give a look. I think it explains why your events don't work as intended.
B
12
S
7
G
7
Posts: 447
Reputation: 4,270

Post » Thu Mar 26, 2015 4:45 pm

still no luck.
i simplified it to make it obvious how it should (or I expect it to work)

Image

this code gives me mixed results. sometimes it waits 1 second so i can attack again. sometimes it resets immediately and i can keep bashing the button attacking a million times (ignoring the 1 second cooldown)

----

I also tried the timer behavior. for some reason it doesnt get called??

Image

what happens is i attack the first time and never can attack again (as if the timer never happened)
Image
B
18
S
5
G
2
Posts: 60
Reputation: 1,575

Post » Thu Mar 26, 2015 5:34 pm

You have to remember that the events run continuously, so "X Is canAttack" is running about 60 times a second, and resetting the timer. Add a "Trigger once", or keep track of whether you have the timer running.
ImageImageImage
B
70
S
19
G
141
Posts: 3,323
Reputation: 83,228

Post » Thu Mar 26, 2015 6:11 pm

("X Is canAttack" is running about 60 times a second, and resetting the timer)
YES.

fixed it by adding another bool:

Image

thanks for the help!
Image
B
18
S
5
G
2
Posts: 60
Reputation: 1,575


Return to How do I....?

Who is online

Users browsing this forum: Husui, mantap100, revengeracer and 18 guests