# Start "Every X Seconds" on event?

Get help using Construct 2

### » Thu Feb 21, 2013 7:38 pm

Is there a way to restart the "every x second" count teach time an event occurs?

ie:

If Mana < ManaMaximum

Every 4 seconds, Add 1 to Mana

The problem with this is if mana = maximum, the 4 seconds are still counting, so on the next tick when mana is less than manamaximum, it adds one to mana immediately. Is there a line of code that can set if mana < manamaximum, count to 4 and THEN add 1 mana?
B
21
S
3
Posts: 450
Reputation: 2,108

### » Thu Feb 21, 2013 7:56 pm

@ome6a1717 - You could setup a variable and use it as a countdown instead.

e.g. set the timer variable to 4, every x Seconds subtract 1, when the variable reaches 0, reset it to 4 (or whatever you need). Then perform any actions you need when the timer is 0.
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

### » Thu Feb 21, 2013 8:42 pm

Hey SpaceApe,

I thought of that, but wouldn't this technically have the same issue? Once the Mana is less than 4, the CountDown variable would start to countdown, but instead of starting at 4, because it had a buffer it would immediately go to 3 seconds and THEN do every x seconds. It does help, but still doesn't fix it.

Unless I'm wrong, which I could be :)

B
21
S
3
Posts: 450
Reputation: 2,108

### » Thu Feb 21, 2013 8:47 pm

Let's say , manamaximun = 5 and mana is a variable
...
Every 4 seconds
-- if mana < 5
---- Add 1 to manaWhiteclaws2013-02-21 20:49:29
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

### » Fri Feb 22, 2013 3:18 am

[QUOTE=Whiteclaws] Let's say , manamaximun = 5 and mana is a variable
...
Every 4 seconds
-- if mana < 5

Hmm...I tried this and it still doesn't work. It seems to run every 4 seconds no matter how you put it. Is there any other way to do this?
B
21
S
3
Posts: 450
Reputation: 2,108

### » Fri Feb 22, 2013 3:26 am

@ome6a1717

You only want the mana timer to start if mana is less than maximum, correct?

If mana < manamaximum, subtract 1 from mana timer
When mana timer reaches 0, add 1 to mana, set mana timer back to 4

Event Conditions: 1) Every X Seconds, 2) Mana < Manamaximum
Actions: subtract 1 from mana timer
-- Sub-Event: Mana timer <= 0
-- Actions: add 1 to mana, reset mana timer

I hope that's clear. :) Sometimes explaining isn't as easy as doing. If you're still having trouble, I can do up a quick capx for you.
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

### » Fri Feb 22, 2013 3:33 am

what if you add another variable to the mana, let's say manaRegen
you can make it boolean

so:
if mana < manamaximum, set manaRegen to true
if manaRegen is true, every 4 second add 1 mana (or maybe you want to use Wait, but I'm not really sure)
if mana >= manamaximum, set mana = manamaximum, and set manaRegen to false

I'm newbie so I don't really familiar with advance thingy, so I try to help with some basics...let me know if it works

cheers
B
11
S
3
G
4
Posts: 56
Reputation: 3,205

### » Fri Feb 22, 2013 4:12 am

[QUOTE=Space Ape] @ome6a1717

You only want the mana timer to start if mana is less than maximum, correct?

If mana < manamaximum, subtract 1 from mana timer
When mana timer reaches 0, add 1 to mana, set mana timer back to 4

Event Conditions: 1) Every X Seconds, 2) Mana < Manamaximum
Actions: subtract 1 from mana timer
-- Sub-Event: Mana timer <= 0
-- Actions: add 1 to mana, reset mana timer

I hope that's clear. :) Sometimes explaining isn't as easy as doing. If you're still having trouble, I can do up a quick capx for you.[/QUOTE]

Hey Space,

This is exactly what I did, and it's entirely possible with my somewhat limited knowledge of C2 I AM, in fact, doing it wrong.

However, when I do this code and set a text box as the mana timer (just to see the effect), when Mana < Manamaximum, the timer goes straight to 3 instead of waiting a second (will sometimes wait half a second, or 1 tick, etc. - depends on when mana < manamximum because the every X seconds is running no matter what).

Hopefully I'm explaining this right?
B
21
S
3
Posts: 450
Reputation: 2,108

### » Fri Feb 22, 2013 2:17 pm

As I think I understand it:

Every 4 seconds might be half way through its "loop" when you are checking so instead of waiting 4 seconds you will only wait the remainder of the 4 seconds.

So how about setting up a global variable (gvManaTimer ?) and increasing this every 1/10th of a second.

then you reset GVManaTimer at the correct time and wait for it to be +40 before you increase you actual mana ?

so you will end up with something like

make GlobalVariable called gvManaTimer

every 0.1 seconds : increase gvManaTimer
------------------

I've used some mana
reset gvManaTimer to 0

is gvManaTimer >40 (ie it's 4 seconds plus since I last reset gvManaTimer)
YES ?    :    add one to mana (if mana is less than it should be)
:    also reset gvManaTimer to 0 to restart its 4 seconds again

this will still have the same problem of maybe starting its loop during the every x seconds but as the time is small then probably not noticeable.

Maybe 0.1 is too short a time - every 0.25 or 0.5 or even 1 second updates ?RamPackWobble2013-02-22 14:27:01
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
59
S
30
G
34
Posts: 1,194
Reputation: 23,767

### » Fri Feb 22, 2013 2:43 pm

Have a look at

mana timer test

going to play with the wait command as this might work (never tried it yet...)RamPackWobble2013-02-22 14:44:11
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
59
S
30
G
34
Posts: 1,194
Reputation: 23,767

Next