How can a variable be shared between two specific functions in a KinematicBody2D script ?

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

The specific functions are _process and _on_input_event.

Thanks a lot in advance.

:bust_in_silhouette: Reply From: HalfTough

You can just create variable inside your KinematicBody2D. It will then be available to all functions within your KinematicBody2D.

extends KinematicBody2D

var myVar

func _on_input_event():
    myVar = "was input"

func _process():
    if myVar:
        print("myVar changed")

If you want variable that will be shared only between those two functions – I don’t think that’s possible. At last not if one of the functions isn’t calling another (and in this case you don’t want to do that).