ID:155757
 
As I'm redesigning my game, I've been thinking on something. In my game, there are a few states you can be in: alive, dead, or deactivated.

mob
var
dead = FALSE
deactivated = FALSE


...but I've been thinking. Is something like the following viable for such a system?

mob
var
state = ALIVE

proc
get_state()
return state

verb
Die()
set category = "BIT"

state = DEAD
src << get_state()

Deactivate()
set category = "BIT"

state = DEACTIVATED
src << get_state()

Splorch()
set category = "BIT"

state = DEAD | DEACTIVATED
src << get_state()

Revive()
set category = "BIT"

state = ALIVE
src << get_state()

Move()
if(state & (DEAD | DEACTIVATED))
return FALSE

else
return ..()

var
const
TEST_VALUE = 0
DEAD = 1
DEACTIVATED = 2
ALIVE = 4


What I have here works (if I'm either dead, deactivated, or both I cannot move) but... yeah. I've never really used bitflags before so I'm not sure if I'm using them right in the first place.
That is technically proper use of them, yes. However, in this case it seems more like you just want an enumerated type, rather than bitflags. Bitflags would be used if the separate states are not mutually exclusive, like ALIVE and DEAD are.
In response to Garthor
I read over the article on Wikipedia for enumerated types (since that's the first time I've heard that term) and... hrm.

I... think it means just using named constants in place of doing just like, state = 1 (which is the same as state = DEAD?)

var
ALIVE = 0
DEAD = 1
DEACTIVATED = 2

mob
var
state = ALIVE

proc
Die()
state = DEAD

Deactivate()
state = DEACTIVATED

Revive()
state = ALIVE