Hello guys! Souls Like stamina system issue:

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vérszem

When the caracter slash with an axe, the stamina bar’s (wich is a TextureProgress) value -= 30. And I created a Timer node, wich used for wait like two seconds after the slash, to refil. It works, but ONLY at the first time, after that the stamina immediately refils. Do you have any idea, how to solve this probelm?

The codepart:

func _on_stamina_timeout():
stamina = true

func _physics_process(delta):
if active == true:
process_weapons()

	
	if stamina == true:
		if s.value < s.max_value:
			s.value += 0.5
:bust_in_silhouette: Reply From: codelyok13

I always have problems with the timer so I just use process since it gives informations in seconds with the ms portion be in the decimal portion of the float value.

enum StaminaState {WAIT, FILL, DRAIN}

var stamina_state = StaminaState.FILLED
var stamina = { "Value": 10,  "MAX": 10 }
var time_to_wait_before_filling_in_seconds = 1
var time_passed = 0

#delta in seconds
func _process(delta):
   match stamina_state:
      StaminaState.FILL:
         #if stamina value less max, increase else keep the same
         pass
      StaminaState.WAIT:
         if time_passed >= time_to_wait_before_filling_in_seconds:
               stamina_state = StaminaState.FILL
               time_passed = 0
         else:
              time_passed += delta
         pass
      StaminaState.DRAIN:
         time_passed = 0

#Any time an action is done

  • Decrease Stamina Value if stamina value greater than 0
  • Switch back to Drain State to reset time

Thank you! It’s kinda working!

Vérszem | 2022-03-31 17:01

make sure in Drain state to make it so that it changes stamina_state to WAIT and that any action switches back to DRAIN

StaminaState.DRAIN:
         time_passed = 0
         stamina_state = StaminaState.WAIT

codelyok13 | 2022-04-01 18:19