It sounds like you're trying to check for the presence of specific flags in a bitfield.
Try something like this instead, which is more readable:
# The `<<` operators performs a bit shift to the left, which can be used to elevate a number to the power of the righthand side quickly (when used with `1` on the lefthand side).
const FLAG_FALLING = 1 << 0 # 1
const FLAG_FLAMMABLE = 1 << 1 # 2
const FLAG_SLIPPERY = 1 << 2 # 4
const FLAG_NONSOLID = 1 << 3 # 8
func _ready() -> void:
# The bitwise `|` operator can be used to combine flags safely.
# `+` can also be used, but it's less safe as it won't prevent you from adding the same flag multiple times (which is invalid).
var block_flags = FLAG_FALLING | FLAG_SLIPPERY
print("Falling: ", has_flag(block_flags, FLAG_FALLING))
print("Flammable: ", has_flag(block_flags, FLAG_FLAMMABLE))
print("Slippery: ", has_flag(block_flags, FLAG_SLIPPERY))
print("Nonsolid: ", has_flag(block_flags, FLAG_NONSOLID))
func has_flag(bitfield, flag):
# The bitwise `&` operator will return a number with all bits "in common" between the two numbers set to `1`, and all other bits set to `0`. If no flags match, the returned number will be `0` since there will be no bits in common between the two numbers.
# Here, we convert it to a boolean since we are only interested in whether
return bool(bitfield & flag)