Bitwise.band(number, number)

shared
Performs a bitwise AND operation on two numbers.

Arguments

Returns

  • number The result of the bitwise AND operation.

Remarks

Note

The `band` function is equivalent to the `&` operator in Lua.

Examples

Checks if the first player has the FL.ONGROUND flag set:

local player = Util.GetPlayerByUserID(1)
local isOnGround = Bitwise.band(player:GetFlags(), FL.ONGROUND) ~= 0

if (isOnGround) then
  print("Player 1 is on the ground.")
end
local player = Util.GetPlayerByUserID(1)
local isOnGround = player:GetFlags() & FL.ONGROUND ~= 0

if (isOnGround) then
  print("Player 1 is on the ground.")
end

Checks if the player has only he FL.ONGROUND flag set:

local player = Util.GetPlayerByUserID(1)
local isOnGroundAndNothingElse = Bitwise.band(player:GetFlags(), FL.ONGROUND) == FL.ONGROUND

if (isOnGroundAndNothingElse) then
  print("Player 1 is on the ground and no other flags are set.")
end
local player = Util.GetPlayerByUserID(1)
local isOnGroundAndNothingElse = player:GetFlags() & FL.ONGROUND == FL.ONGROUND

if (isOnGroundAndNothingElse) then
  print("Player 1 is on the ground and no other flags are set.")
end