I wanted to make a script like:

var number = 0
func process():
  if number.change_the_value:
something happens

You can't track variable changes like (at least I don't think so) but you can create a property (similar to a variable) that has a getter/setter function which is called when it is changed (you are basically calling a function instead of directly changing the variable). You can look in the GDScript documentation for how get/set works. You didn;'t specify which version of Godot.

The you need to use setget :

var number: float=0 : set = setNumber
func setNumber(v: float):
prints("You change the number !")

Why do you need to know when it changes? I mean if it's changed by the code, the code knows when it changed it 🙂. If it's being altered via editor then use setget as already suggested.

    6 months later

    xyz Because a variable can be changed by another script, e.g.

    `
    @onready var Control = $UI

    func _ready():
    Control.TimesOpened += 1
    `

    In this example, the control node doesn't know that the variable has changed, although in this case you could probably just use a signal.

    • xyz replied to this.