How to use this |= ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Decemberfrost

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

:bust_in_silhouette: Reply From: Calinou

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.

thank you so much!!

Decemberfrost | 2021-10-29 17:59

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

Decemberfrost | 2021-10-29 18:23

+= 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.

Calinou | 2021-10-30 15:28