Start "Every X Seconds" on event?

0 favourites
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • 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?

  • 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.

  • Hey SpaceApe,

    Thanks for the reply.

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Let's say , manamaximun = 5 and mana is a variable

    ...

    Every 4 seconds

    -- if mana < 5

    ---- Add 1 to mana

  • Let's say , manamaximun = 5 and mana is a variable

    ...

    Every 4 seconds

    -- if mana < 5

    ---- Add 1 to mana

    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?

  • 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.

  • 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

  • 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.

    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?

  • 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 ?

  • Have a look at

    mana timer test

    going to play with the wait command as this might work (never tried it yet...)

  • OK Wait works also so maybe a better choice ?

    mana test using wait

    edit

    this sets the 4 second timer the first time you use mana and it keeps increasing your mana every 4 seconds but it does not restart the 4 seconds every time you use mana if below 100%

  • Hey RamBam,

    Thanks a lot for looking into this. I don't use the beta version of construct, so I can't open your file. If you wouldn't mind, could you post an image of the code?

    Thanks!

    Steve

  • While grabbing the value of the timer and checking it to see if 4 seconds have gone by sounds good, I would probably have used WAIT myself.

    Here is the screenshot of RamPackWobble's code:

    <img src="https://dl.dropbox.com/u/85412219/forumposts/waitcount.png" border="0" />

  • My solutions

    Embed the "every X seconds" into a group.

    Enable when cast spell

    Disable when mana is 100%

  • Here is a copy of the first version code

    <img src="https://dl.dropbox.com/u/143636437/temp/screen%20grab.png" border="0" />

    I like the idea of using a group turned on or off...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)