Topic was automatically imported from the old Question2Answer platform.
Asked By
lucasfazzi
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.
I already have the answer in my head, but I can’t elaborate on code
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