Change game states trough python

What I want to know is how do u change states trough python?

I thought it would’ve been like this:

you define your actuator in a variable (obviously the state actuator)

my_variable = controller.actuator[‘actuator_name’]

my_variable.states[0] => but this does not seem to work :frowning:

owner.state = 1

Keep in mind it’s a bit mask, so…
1 = state 1
2 = state 2
3 = states 1 & 2
4 = state 3
5 = states 3 & 1
etc.

Thx for the quick reply.

I’ll have to look up that bit mask then :wink:

uhm, guys where can i find info on that bit mask thingy. (bit mask related to blender logic states)
And how do u check what state your in? cause get.state is deprecated, don’t find anything similar.

A bit mask is leterally a bit mask. 1 = Active, 0 = Inactive. So you need to imagine your number in binary to understand it:

1 = 00000001
2 = 00000010
3 = 00000011
4 = 00000100
5 = 00000101
6 = 00000110
7 = 00000111
… up to 255 for 8 bits.

For easier use instead of writing an integer, use a bit literal:
variable = 6
variable = 0b00000110

P.S To check if a given state is active, you use a bit by bit operator, for example to check if the state 6 or 2 are active, you do:

if 0b00100010 & own.state: print(“Any of those is active”)
if 0b00100000 & own.state: print(“Only the state 6 is active”)
if 0b00100010 & own.state and own.state != 0b00100010: print(“Any of 6 or 2 are active, but not both”)

in short, power of 2

[1,2,4,8,16,32,64,128,256,512,1024,2048,4096…]

numbers missing from this list must be added from the existing members

1 = 1 # already in the list
2 = 2 # already in the list
3 = 1+2 # not in the list so add position 1 AND 2, now you have 1 + 2 = 3
4 = 3 # already in the list
5 = 3+1 # not in the list so add position 3 AND 1, now you have 4 + 1 = 5
6 = 3+2 # not in the list so add position 3 AND 2, now you have 4 + 2 = 6
7 = 3+2+1 # not in the list so add position 3 AND 2 AND 1, now you have 4 + 2 + 1 = 7
111 = 7+6+4+3+2+1, and you have 64+32+8+4+2+1 = 111