Separating a flag in Lua

CST1229

back after too much time
So I'm trying to make a Lua script that accesses flags from the player.
However I don't know how to separate a single flag from the 1 big number that the flag userdata values provide.
I may be handling userdata structures wrong as well.
Here is my code so far:

Code:
local function reverseGoop(p)
     if (p.mo.eflags|MFE_GOOWATER == true) then
    p.mo.eflags = p.mo.eflags - MFE_GOOWATER
    print("In goop!")
    end
end

 addHook("PlayerThink", reverseGoop, MT_PLAYER)
Can someone please tell me how to separate a flag bit from a variable?
 
Flags can be removed by using the binary intersection operator (&), also called bitwise AND. You're going to be intersecting the current bits in the variable with the negation of the bit you'll want to remove, like so:

Code:
p.mo.eflags = p.mo.eflags & ~MFE_GOOWATER
 
Flags can be removed by using the binary intersection operator (&), also called bitwise AND. You're going to be intersecting the current bits in the variable with the negation of the bit you'll want to remove
However I also need to check for the flag too, your solution doesn't seem to work with it.
(EDIT: Nevermind, I figured it out. All you need to do to check the flag is to AND the flags value with the flag you want to check. Plug that into an if statement and voila! Or just use P_IsObjectInGoop.)
 
Last edited:

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top