That should set the object’s state to number 3, right? (top row, 3rd from the left) And it works like copy state?
It don’t.
I tried with a scene with the default cube and made five states. Every state had an always actuator - and - movement. Every state had a movement or rotation on different axis so there’s no mistake which state is active. Then a script in the first state with the above code and tested it with different numbers in setState(). State 2 and 3 looks to both be number 2. 4 looks like 3 should. 5 like state 2 again. Then nothing until state 10 which again acts state 2. No warning in the console.
am I doing something completely wrong? if this looks correct I can post a blend if you don’t want to make this simple scene yourself.
The state of an object is a bit mask. The state of a controller is a single bit, numbered from 1 to 30 while the actual mathematical bit number is 0 to 29.
Graphically, the state is represented as collection of 30 button, each corresponding to a bit. The top row correspond to bits 0-14 and the bottom row to bits 15-31.
So if you want to set state 3, you have to set the state mask to 1<<(3-1) = 1<<2 = 4.
This complicated and it would be better to define constant values for each state bit: KX_STATE1 -> KX_STATE30 so that you could use setState(KX_STATE3), If you want to have more than one state bit set, you could use the | operator: setState(KX_STATE3|KX_STATE4).
i made a supah elegant function for that, you just pass the states you want to activate.
def getStateBitmask(*ac_states):
"""
Return a state bitmask from a list of integers
By cyborg_ar
"""
mask = 0
for state in ac_states:
state = int(state)
if state > 0 and state < 31:
mask = mask|(1<<(state-1))
return mask
#test it!
print getStateBitmask(1,2,3,4)