-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a boolean XOR operator to GDScript #230
Comments
Well, for booleans, it's basically equivalent to the |
I'm so used to ^ in c++ i didn't even think about using != in fact |
This can be achieved with the following one-liner: $Panel.visible = not $Panel.visible
# Or:
$Panel.visible = !$Panel.visible GDScript also offers the some_texture.flags |= Texture.FLAG_FILTER |
Yes, i can agree that my request is not that great in retrospective. |
C++ doesn't have a boolean/logical XOR operator either. |
Yes but you can still use it on bools |
The difference between print(123 != "string") # Error (See godotengine/godot#26375.) And this is correct: print(123 && "string") # True
print(123 || "string") # True Even if you accept 26375, # print(123 xor "string") # False
print(bool(123) != bool("string")) # False
print(!123 && "string" || 123 && !"string" ) # False |
While != works in my scenario I don't think ^^ is equal to !=. I tend to think of != and == as having lower priority than && and ||. The way I am thinking about it they always occur last. |
Mixing the |
Closing due to lack of support – see the above discussion. |
@Calinou There was not even a vote of Twitter experts on this issue. How can you judge the degree of support by 3 votes? And while I'm on the subject of operators, this proposal has support: 13 : 0. Where is my exponentiation operator? 😃 As for the division operators, I'm disappointed. I could say a lot, but this topic is not the place for that, and the original discussion is blocked. I just want to say that if 992 people voted against, then this is not a reason to hopelessly block the discussion. A 58 : 42 ratio is not 95 : 5 (moreover, the sample was not representative). With such figures, not the majority should decide, but objective facts. |
if object xor condition:
do_something()
if object xor number:
do_something()
if object xor vector:
do_something()
# vs
if is_instance_valid(object) != condition:
do_something()
if is_instance_valid(object) != bool(number):
do_something()
if is_instance_valid(object) != (vector != Vector2.ZERO):
do_something() |
Ended up here looking for how to do xor on bool. Is the state of this discussion still actual in 2021? Yeah operator != messes up precedence, I can use it but it's a poor man's replacement for |
Yes, no XOR operator was added in the If you really need it often, you can probably write a method for it and expose it in an AutoLoad. |
OMG, why does XOR bother you so much? Check out my comments above for an explanation of how XOR differs from |
Every feature has a maintenance cost 🙂 We need to balance the number of features versus this cost. |
I don't believe that maintaining this feature is too expensive. This is ridiculous. There are many much more controversial features than this unfortunate operator. Arguing that |
Godot 3.3.1
example:
|
@luislodosm var my_bool = 1
my_bool &= 0
print(my_bool) # 0 |
It's useful when you need to check multiple conditions, for example:
|
You can use: var all_visible = true
for node in nodes:
all_visible = all_visible and node.visible
# Or:
# all_visible = all_visible && node.visible You can open a proposal to add var all_visible = true
for node in nodes:
all_visible &&= node.visible But we don't need to mix logical and bitwise operators. print(1 & 1) # 1
print(1 && 1) # True |
Can't think of any cases where it'd improve code. This is faster and easy to read:
|
|
nooo, that's not how XOR works, if
in cryptography there's such a thing as a one-time pad, you generate a stream of random bytes the size of the data you want to encrypt, that stream acts as both encryption and decryption key:
|
Describe the project you are working on:
Working on a simple game.
Describe the problem or limitation you are having in your project:
i was just trying to toggle a Panel visibility on and off
Describe how this feature / enhancement will help you overcome this problem or limitation:
It could be written very naturally like any other language, typing that much code for something that simple seems weird and unpractical
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
See below
Describe implementation detail for your proposal (in code), if possible:
the syntax could be something like :
$Panel.visible = $Panel.visible ^^ true;
additionally a ^^= operator could be provided
$Panel.visible ^^= true;
If this enhancement will not be used often, can it be worked around with a few lines of script?:
it can definitely be replaced by a few line of script, but it also seems like a decent language should have that operator
Is there a reason why this should be core and not an add-on in the asset library?:
I guess it can't be an addon i that case
The text was updated successfully, but these errors were encountered: