2
$\begingroup$

I've been dabbling in Blender's Game Engine, so I thought it was time to take it to the next level and use scripts to control my game, but now I have a problem; I keep getting this error (only printing error message):

mainScript.py, line 28
   if PlayerControls.playerMain['isInCover'] == 0
                                                ^
SyntaxError: invalid syntax
location: <unknown location>:-1

My code:

def toggleProne():
  if PlayerControls.playerMain['isInCover'] == 0
      PlayerControls.playerMain['isCrouched'] = 0
      PlayerControls.playerMain['isStanding'] = 0
      PlayerControls.playerMain['isProne'] = 1
  return;

Removing the if-statement and adjusting the indentation (as a result of the removed if-statement) allows the code to be compiled - until it finds the next if statement and errors out.

$\endgroup$

1 Answer 1

1
$\begingroup$

To write an if statement in python you need a colon at the end of the condition then the rest gets indented.
Like this

if a == b:
    print("yep")

So your code would be like this.

def toggleProne(): 
    if PlayerControls.playerMain['isInCover'] == 0:
        PlayerControls.playerMain['isCrouched'] = 0
        PlayerControls.playerMain['isStanding'] = 0
        PlayerControls.playerMain['isProne'] = 1
    return;

Personally, I would use a var for PlayerControls.playerMain, it would save you from having that whole thing four times.

$\endgroup$
3
  • $\begingroup$ Thanks a lot, really is the small things that cause the biggest of problems in code! ;) $\endgroup$ Commented Sep 6, 2016 at 0:01
  • 1
    $\begingroup$ indeed. computer are so picky. they do exactly what we tell them to do, even if that is not what we meant. $\endgroup$
    – David
    Commented Sep 6, 2016 at 0:03
  • $\begingroup$ @David "HAL, make coffee, add milk and 10 tablespoons of sugar" ... "Sure, Dave, I can do that." $\endgroup$ Commented Sep 6, 2016 at 22:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .