It's probably an easy question, but I'm so stuck I can't think of alternatives anymore;

I have a VAR A that changes over time; basically it starts with value 1 and then turns 2 and then 3 and so on.

so I need to do an action that checks each change from VAR A and determines another action for another VAR B; for example, "when the difference from VAR A to VAR B is X then do this; when the difference from VAR A to VAR B is X + 1 then do that" and so on ever.

in Engine

Use a setter function, and put the logic check in it.

https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html#setters-getters

var a setget _set_a
var b

func _set_a(newA):
a = newA
if b - a == x:
# do something
pass
if b - a == x + 1:
# do something else
pass
by (342 points)
selected

I tested them both and it came closer than I imagined.

anyway thank you guys both were very helpful

+1 vote

For the difference you can use abs (), abs (a-b) is the same as abs (b-a), then you can do:

var a = 2
var b = 5
var x=0
var compare =true

func _process(delta):
if abs(a-b) >= x and compare:
some_action() #continue call the function while abs (a-b) =>x is true
compare = false#we avoid the above
elif abs(a-b) > x and (a > 4) or (b > 4): #others rules
other_function()
b=4
elif abs(a-b) == 2:
print("Be careful here, if the difference jumps from 1 to 5, this will never be
printed as expected")
else:
pass

func some_action():
pass
func other_function():
pass
by (2,060 points)