How to make a working cooldown function

Get help using Construct 2

Post » Sat Apr 01, 2017 3:05 pm

I'm trying to make a cooldown function that sets my game on pause for 5 seconds.

I have a function that I call in the code with a sub event saying "Every X seconds" which I have set to 1 to fire it every second. But somehow the timer is running only once. Any ideas what might be wrong?

Image

Edit. Updated with screenshoot
Last edited by janlindso on Sat Apr 01, 2017 3:31 pm, edited 2 times in total.
Image
B
14
S
4
Posts: 145
Reputation: 1,948

Post » Sat Apr 01, 2017 3:16 pm

You said you are settings something to 1 every X seconds, but are you settings it back to 0 after that?
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Sat Apr 01, 2017 3:32 pm

andreyin wrote:You said you are settings something to 1 every X seconds, but are you settings it back to 0 after that?


I have updated with a screenshot.
Image
B
14
S
4
Posts: 145
Reputation: 1,948

Post » Sat Apr 01, 2017 3:46 pm

Your every x seconds is a sub event of a triggered event, which only fires once every time the function is called.

(On function only lasts for one tick)
Mistakes were made.
B
52
S
26
G
111
Posts: 1,623
Reputation: 62,667

Post » Sat Apr 01, 2017 3:51 pm

oosyrag wrote:Your every x seconds is a sub event of a triggered event, which only fires once every time the function is called.

(On function only lasts for one tick)


That was what I suspected. Any ideas how I could make this work?
Image
B
14
S
4
Posts: 145
Reputation: 1,948

Post » Sat Apr 01, 2017 3:53 pm

That 's too complicated.
Just use an Instance variable + TIMER.

Example: Instance Var: ATTACK1
On [Attack] | Set ATTACK1 to 1
. | Start Timer

On Timer | Set ATTACK1 to 0

Disable attack when ATTACK1 is 1.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Sat Apr 01, 2017 4:07 pm

MPPlantOfficial wrote:That 's too complicated.
Just use an Instance variable + TIMER.

Example: Instance Var: ATTACK1
On [Attack] | Set ATTACK1 to 1
. | Start Timer

On Timer | Set ATTACK1 to 0

Disable attack when ATTACK1 is 1.


Well, it not for an instance, but for the whole game. Several objects will be hidden.
Image
B
14
S
4
Posts: 145
Reputation: 1,948

Post » Sat Apr 01, 2017 4:18 pm

janlindso wrote:Well, it not for an instance, but for the whole game. Several objects will be hidden.

Same concept. Use Global Variable instead.
Global Variable: PAUSED = 0
Create a random sprite, a small pink box(or any color you want) that's set invisible that serves only as a timer holder.

On PAUSED = 0 | [EVERYTHING in your game]
On [Paused Button] pressed | Set PAUSE to 1, Start Timer...

You get the picture.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Sat Apr 01, 2017 4:28 pm

Use a GAMESTATE global variable - 0 is normal, 1 is pause. Have your trigger function set GAMESTATE to 1

Have a separate counter event.

If GAMESTATE is 1
Every X seconds - Do Countdown
-- Cooldown < 1 - Set GAMESTATE 0

Edit: Didn't see mpplant already replied. Yeah basically what he said :D
Mistakes were made.
B
52
S
26
G
111
Posts: 1,623
Reputation: 62,667

Post » Sat Apr 01, 2017 6:52 pm

Yeah, worked fine!
Image
B
14
S
4
Posts: 145
Reputation: 1,948


Return to How do I....?

Who is online

Users browsing this forum: Jackriduk, kiki4construct, osek95 and 19 guests