Bit Operations Script - AND | NOT | XOR | Left Shift | Right Shift

Crayta unfortunately uses an older version of lua without bit operation support, so this script was made to fill the gap.

Installation

  • Find Bitwise Operatorts in the community packages
  • Add bitScript to whichever script needs it (i.e. gameController)

Usage
In your gameController script, or where ever your script is, define the following local variable:

local bitScript = {}

In your init script, add the following:

function GameControllerScript:Init()
  bitScript = self:GetEntity().bitScript
end

Usage

AND

bitScript.band(val1, val2)

NOT

bitScript.bnot(val)

XOR

bitScript.bor(val1, val2)

LSHIFT

bitScript.lshift(val, displacement)

RSHIFT

bitScript.rshift(val, displacement)
3 Likes

Hi there - I used this recently and it is very useful. I noticed a minor typo (possible I introduced it somehow?) in the script where lshift shows as mshift in the code.