Can't assign to operator (Python script error)

Hi all,

I was making my first Python script, for the menu selector, but I have no idea on how to do this, so I have based it in a movement script, but when I run the script, the console says to me in the line 121 there are an error and can’t assign to operator.

Here are a screenshot of the script and the line:

PD: If I can’t make the selection script base in a movement script, tell me how to do the menu selection script, please!

Firstly, line 110 should be


seleccion = controller.sensors["seleccion"]

next of, and is just a conditional comparator.
If you want to set more than one value to False, just create a function to do so:


def set_false(*variables):
    return [False for i in range(len(variables))]
        
x, y, z = set_false(x, y, z)

Or use list unpacking:


x, y, z = [False, False, False]

or just set each one to false:


x = False
y = False
z = False

Then, you’ve got 6 returns?! Return will quit the function, sending the argument with it. Therefore, you can only ever have one return. If you want to send all those variables back, use a list or tuple


return [select_sp, select_mp, select_opt, select_exit]

or, as python assumes it is a tuple:


return select_sp, select_mp, select_opt, select_exit

But, you don’t need this! Just use a property action actuator, and add or remove one from the property, then animate the selector to be at position 0, 1, 2 or 3, and by increasing the property, the selector will be at that position.

Oh god, thanks!

Sometimes I think I complicate my own work D:

Menu navigation now done :smiley:

Remarks:


if seleccion.positive == True:
  ...
elif seleccion.positive == False:
  ...

processes needles code. Better


if seleccion.positive:
  ...
else:
  ...