Standalone expression (top down game)

Godot Version

`4.4.stable’

Question

func _on_runcd_timeout() -> void:
	if Input.is_action_pressed("run") == false:
		staminaGain == true
	elif Input.is_action_pressed("run") and velocity.x or velocity.y > 0:
		staminaGain == false

in this code the staminagain == (boolean) are both stated to be standalone expressions and wont do anything. Runcd is a timer and this is for recharging stamina

Double equal signs (==) are used to COMPARE values.
This essentually translates to (Is staminaGain true?) and will return either true or false.

A single equal sign (=) will SET a value instead.

In your case, you simply compare if staminaGain is equal to true or not. This is expected behaviour in any programming language.
What you (probably) want is a single equal sign, to ASSIGN a value to staminaGain.

func _on_runcd_timeout() -> void:
	if Input.is_action_pressed("run") == false:
		staminaGain = true
	elif Input.is_action_pressed("run") and velocity.x or velocity.y > 0:
		staminaGain = false
2 Likes