Topic was automatically imported from the old Question2Answer platform.
Asked By
Tort
Hey. Advise how to optimize expression. if animation_position > 0.2 and animation_position < 0.4: - too long. if 0.2 < animation_position < 0.4: - and it doesn’t work like that.
So, you’re trying to optimize the physical length of the expression - just to make it shorter to type? Can I ask why?
Really, there’s not much you can do to the expression itself other than shortening the variable name or replacing and with &&.
Other than that, you could write a function to perform the test, which might give you a shorter calling syntax depending on your naming conventions. Something like the following (typed directly here, so untested):
if isBetween(animation_position, 0.2, 0.4):
# do something...
func isBetween(value, low, high):
return value > low && value < high
# action in a certain position of the animation
func check_anim_pos(anim_player, value):
if anim_player.current_animation_position > value - 0.02 and \
anim_player.current_animation_position <= value:
anim_player.seek(value + 0.01)
return(true)
else:
return(false)