Personally, I’ve always just used code like this:
if (LeftRight == true):
player_offset.x = abs(player_offset.x)
else:
player_offset.x = abs(player_offset.x) * -1
Or another thing I sometimes use:
player_offset.x = abs(player_offset.x)
if (LeftRight == false):
player_offset.x *= -1
I’m not sure if it is better or not, it’s certainly longer, but that’s generally what I use and it seems to work okay most of the time. I generally like longer bits of code that are (in my opinion) easier to read than shorter one liners. It is just my personal preference.
I know in JavaScript you can use ternary if statements, and apparently it is supported in GDScript through this syntax a if x else b
. So, to use it with a Boolean, it would look something like this (in theory, untested)
player_offset.x = abs(player_offset.x) * (1 if LeftRight else -1)
Not sure how helpful it would be, but I might consider trying ternary if statements since they are designed, more or less, for this kind of thing.
As for performance on any of the above I wrote, I don’t know. I imagine not converting a Boolean to an Integer will yield slightly better performance overall, but likely it is to be minimal. Personally, I am of the mind to not worry about optimizations until needed, since it is easy to spend lots of time optimizing without knowing whether it will yield better performance.
Hopefully this helps!
(Side note: Welcome to the forums!)