How can a condition be tracked in every frame and if it is true, then perform an action once?

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

How can a condition be tracked in every frame and if it is true, then perform an action once?

example:

func _process(delta):
    if something:
        print(true)
    else: return

This code will output each frame “true” if the condition is true.

How to make sure that “true” is displayed once when the condition is true?

:bust_in_silhouette: Reply From: imjp94

Add a variable to your script to track the “once” state:

var once = false

func _process(delta):
    if something and not once:
        print(true)
        once = true