Godot: Missing Bool XOR from GDscript

Created on 12 May 2018  路  4Comments  路  Source: godotengine/godot

Godot version: 3.0.2

Issue description:
GDscript is missing bool xor.

Steps to reproduce:
If you try:

var one = true
var two = false
var three = one^two

You get an error

archived enhancement gdscript

Most helpful comment

There's the cheap solution: var three = one != two.

The xor operator (^) is meant for bitwise operations. I wonder if it could be extended to work as a logical operation as well.

All 4 comments

There's the cheap solution: var three = one != two.

The xor operator (^) is meant for bitwise operations. I wonder if it could be extended to work as a logical operation as well.

Oh, thanks

As per the discussion on #22740, adding a xor operator for booleans wouldn't have any practical use as it's the same truth table as the != operator, and it's not a common feature in programming languages to extend it to bools.

xor operator would still be good imo, I actually tried it first before figuring out I could use !=. There's also a slight difference in semantics: "flip if differ" and "not equal", despite the fact that the truth table is the same.

Adding xor operator for booleans can also prevent users to accidentally apply xor/!= operator on integers, throwing parser error in typed GDScript (3.1).

Was this page helpful?
0 / 5 - 0 ratings