Error that is not an error

What is wrong with this it is saying that controller_1 is not a thing yet I have it in port selection.
def controller_1.buttonL1.pressed()

CONVEYER.spin(FORWARD)

def controller_1.buttonL1.released()

CONVEYER.stop

def controller_1.buttonL2.pressed()

CONVEYER.spin(REVERSE)

def controller_1.buttonL2.released()

CONVEYER.stop

1 Like

Ok that changed but now it is saying buttonL1 is an error

It might be missing the point, but you need a colon at the end of each def line. (And indented CONVEYER lines). Unless that works?

What sort of error is it giving?

1 Like

Invalid syntax error

Yeah… I believe you need a colon at the end of each function line.

def controller_1.buttonL1.pressed():
    CONVEYER.spin(FORWARD)

The only error is on the buttonL1 codeimage
What is weirder is that in the next line buttonL1 is not an error

ok, too much misinformation.
pressed needs a callback function just like C++


def pressed_callback():
  brain.screen.print_at("pressed", x=10, y=40 )

def release_callback():
  brain.screen.print_at("release", x=10, y=40 )


controller_1.buttonL1.pressed(pressed_callback)
controller_1.buttonL1.released(release_callback)


5 Likes

Not too sure. Can you send a screenshot of more of the window in case it’s something else. (By the way, : at the end of the line, you have a .).

I put colons in and it did not help

image

Do what jpearman told you to do.

4 Likes

It didn’t help the current problem, (which @jpearman has a solution for), but it will solve later problems.

image
Still says buttonL1 is an invalid syntax

You didn’t copy the code.
you cannot do this (assuming controller_1 is defined as a controller)

def controller_1.buttonL1.pressed():

do this.

def pressed_callback():
  CONVEYER.spin(FORWARD)

def release_callback():
  CONVEYER.stop()


controller_1.buttonL1.pressed(pressed_callback)
controller_1.buttonL1.released(release_callback)

3 Likes


It is defined as controller one. The only error is that it says buttonL1 is not a thing

yes, because you keep putting “def” in front of it which is invalid Python

1 Like

I took it out and the error is off of L1 but it is on CONVEYOR

That happened after I deleted the colons which the error was on after L1 but before conveyer

based on your screenshot, you need something like this.

def conveyer_forward():
  CONVEYER.spin(FORWARD)

def conveyer_reverse():
  CONVEYER.spin(REVERSE)

def conveyer_stop():
  CONVEYER.stop()

controller_1.buttonL1.pressed(conveyer_forward)
controller_1.buttonL1.released(conveyer_stop)
controller_1.buttonL2.pressed(conveyer_reverse)
controller_1.buttonL2.released(conveyer_stop)
3 Likes

Thank you so much. This works perfectly