How do I make a stoppable timer for stamina bar ?

0 favourites
  • 4 posts
From the Asset Store
Tabata timer
$9.99 USD
Template for Tabata timer, fully documented in comments and video
  • Hello, First I am sorry for my bad english, I do my best <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    I try to make a stamina bar. If the player run, he loose his stamina. If he don't run for 3 seconds, his stamina regenerate. But I have some issues with this 3 seconds timer... Here is my code :

    imgur.com/a/kOtBi

    If Maj is pressed, Stamina over 0, and player is not stationary ---> The player run (100 is the walking speed). And he loose stamina.

    imgur.com/a/yP41A

    And here is where i am stuck. I try to do : If the stamina is under 100 (the maximal level) and the player don't have the running speed ---> Wait 3 second before the stamina start regenerate.

    But I want when the player start another action that consume stamina, the 3 second timer reset and restart at 3 second when this action is over. for finally regenerate the stamina at his maximum while the player don't re-consume his stamina.

    With the actual code, If the player run while the stamina start regenerate, the stamina keep regenerating immediately after the player stop running without waiting 3 seconds.

    Can you help me with this ? i'm realy stuck...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello,

    I think that you should look the Timer behavior https://www.scirra.com/manual/167/timer

    Use a timer to trigger regeneration and stop the timer when you consume stamina.

    Tell us if you need help with timers <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Thanks for the tips, I totaly forgot about the Timer behavior.

    I successfully made the timer, from 0 to 3, If the player run again the Timer restart like I want. All is perfect, except I don't know how to start the stamina regeneration when the timer made his 3 seconds. They are no condition trigger ? How can I do ?

  • I found ! Thank you for the timer behavior tips !

    The "How to" for who need the same thing (I don't put any screenshot or project file because i'm not at home, I just have the real "Potato Internet" here.)

    Create your stamina bar and a global variable named "Stamina". You can found some tutorial on the Internet for making a stamina bar who moved with your "Stamina" variable.

    I set the global variable "Stamina" to 100.

    My stamina bar have 4 behavior : The "Pin" behavior because my stamina bar follow the player. The "Timer" behavior for the little timing before it start regenerating. And two "Fade" behavior, one for the Fade In, the other one for the fade out (I want my bar to be invisible after 1.5 seconds if the stamina is full).

    For the two "Fade" behavior, name the first one "Fade_In" with the settings : "Yes", "0.5", "0", "0", "No". And the other one named "Fade_Out" with the settings : "No", "0", "1", "1", "After fade out".

    And the code :

    If Keybord "Maj" is down, AND if "Stamina" over 0, AND if the speed of the player is under the walk speed. -----> Set the player speed to "run speed", subtract the stamina (0.7 for me). stop the timer (inser your timer tag, can be anything, that doesn't matter), and desactivate the "Start_Stamina_Regen" group (we gonna create it later).

    If Keybord "Maj" is released -----> Set player speed to "walk speed".

    If "Stamina" (global variable) is under 100, AND the speed of the player is under the "run speed" -----> Start the timer of the stamina bar for 3 seconds, "Once" with the tag "Stamina_Regen"

    If "On Timer "Stamina_Regen"" condition is true ----> set group "Start_Stamina_Regen" activated.

    CREATE A NEW GROUP named "Start_Stamina_Regen" (activated by default).

    put in the new group : : Every 0.05 seconds, add 4 to "Stamina" (global variable).

    (in no group this time) If "Stamina" (global variable) is equal or over 100 -----> Set "Stamina" to 100, set group "Start_Stamina_Regen" to deactivated, Call the function "Stamina_Bar_Fadeout" (we gonna create the function later). set group "If_StaminaUnder100" to activated (we gonna create the group later).

    If "Stamina" (global variable) is under 0 ------> Set "Stamina" to 0, set the player speed to "Walk speed".

    CREATE A NEW GROUP named "If_StaminaUnder100"

    put in it : if "Stamina" under 100 ------> Call function "Stamina_Bar_Start" (we gonna create the function later), and set the group "If_StaminaUnder100" to deactivated.

    (in no group this time) : on function "Stamina_Bar_Start" ----> Create the stamina bar were you want with your settings, you can Pin it on other objects like me if you want. and Start the "Fade_In" behavior.

    On function "Stamina_Bar_FadeOut" -----> Start the "Fade_Out" behavior.

    Sorry for the long post.

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