I believe those are bit values that you’re looking at, but I’m not 100% sure.
>>> a = 5
>>> a & 2
0
>>> a & 1
1
>>> a & 4
4
A quick tooling around in the Python interpreter helped me out here. In the above example, I assign a value of 5 to the variable a. In a computer, the number 5 which is comprised of four individual switches, or bits: 1, 0, 0, and 1. You add up bits to get individual numbers. For the number 5, the left-most 1 represents a 4, and the right-most one represents 1. 0’s are ignored, so to speak. Bits go up from right to left, and rise in order of magnitude as they go up, i.e.
Bit Position: _0____0____0____0___0___0___0___0
Bit Value: __128__64___32___16___8___4___2___1
Ignore the underscores, that’s just the way that could get them in columns. As an example, a byte is made up of eight bits, and can represent a number between 0 and 255, like above. When all eight bits are set to 1, the value adds up to 255. Higher numbers require more bits.
Anyway, we can do a bit operation with the & operator that compares the bits between two numbers. The & operator in particular compares the bits to see if they match.
In the above example, I do ‘a & 2’ to compare the two numbers - a with a value of 5, and the number 2. Since the variable a has a value of 5, its ‘bit representation’ is 1001. 2’s representation is 10 (or 0010). There are no common bits between those, so the value returned is 0 - no bits match.
On the other hand, both ‘a & 1’ and ‘a & 4’ work because both share bits (the returned value is a number that’s composed of the matching bits, if I am correct). 5 and 1 only share one bit, the right-most one that represents a 1, and so that’s the result. With ‘a & 4’, both numbers (5 and 4) share the left-most bit, which is a 4. That’s the result of that operation.
All of that is to say that the state variable is a single number that represents the currently active states. You can use the ‘&’ operator to compare the state bit number to the object’s state variable and see which ones are active. Note, though, that the state numbers increase in magnitude, not in order.
What this means is that state 1, 2, and 3 aren’t ‘1, 2, 3’, but rather are ‘2^0, 2^1, 2^2,’ and so on. In other words, if you want to check if state 3 is on, use
obj.state & 4
As that will check the 3rd bit, which corresponds to the third state.
EDIT: P.S. This is good, though, because it allows you to check multiple states at a time. For example, you can see if the 1st, 2nd, and 3rd states are enabled:
states = 1 + 2 + 4 # 1st, 2nd, 3rd bits = 1, 2, 4
print (obj.state & states) # see if they're on
I’m not super knowledgeable about this, though.