# Checking if boolean true or false not working

I'm trying to make my character jump using python script. And the character jumps but I want to check if the character is already jumping, and if he is, then not be able to jump again. But for some reason this code doesn't work.

# this triggers when I press space.
if isJump.positive:       #<-- this one doesnt work. but it still prints 'jumped'
if jumping == False
cont.activate(j)
jumping = True
print("Jumped")
cont.deactivate(j)

# this triggers when I collide with an object with a property 'ground'
if collide.positive: #<-- This whole block works fine
jumping = False
num = 0
print(num)
cont.deactivate(j)

• can we see the rest of the code please? this will help us help you. – Scalia Feb 8 '16 at 19:42

You store the current state in an intermediate variable. This can't work. You need to store it in a storage that will survive at least till the next call access. I wondered that you did not get any errors.

There are many ways to solve that issue.

# FSM (build in state machine)

One way is to use the build-in state machine.

You can define a "jumping" state that, (when current) tells the character is currently jumping. On the other hand, if it is not current the character is not jumping. You do not even need Python to do that.

any state can transit to jumping state:

The jumping state cares the jump e.g. playing animations, detecting collisions and switch to other states

# Property

You can create your own state machine. E.g. by using a property of the game object:

jumping = cont.owner.get("jumping")

# this triggers when I press space.
if not jumping and isJump.positive:
cont.activate(j) # what is a "j"?
cont.owner["jumping"] = True
print("Jumped")
cont.deactivate(j) # this will not take effect

# Better separate start jumping from jumping.
# This code does not need to be executed when there is no jumping, regardless of the collision sensor result.

if jumping and collide.positive: #<-- This whole block works fine
cont.owner["jumping"] = False
num = 0
print(num)
cont.deactivate(j)


There are much more ways. I hope it helps a bit.