0 votes

I dont know how it works. I also made this to check:
var a = 0
var b = 1
print(a |= b)
But it wont allow me, it says unexpected assign tho I assumed it already sincr Idk what it bitwise, in the code I saw, that kind of assignment works without error.

I just want to know how it works, how to use it, or when to use it.
Its been a couple of days searching, this is my last card. Sorry

Godot version 3.3.4
in Engine by (28 points)

1 Answer

+1 vote
Best answer

The correct form to use in your case is:

var a = 0
var b = 1
# Bitwise OR without assignment (no equals sign).
print(a | b)

As for bitwise OR assignment, it needs to be used on its own line as Godot doesn't allow assignments within expressions:

var a = 0
var b = 1

a |= b
# `a` is now 1.

a |= b
# `a` is still 1.
by (11,889 points)
selected by

thank you so much!!

...oh, I just tested it, so it was like += for Integers. dang~

+= does not always behave like |= depending on the number on the right side of the operand. The former is addition, the latter is bitwise OR.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.