The program I wrote gives me an error on a specific line even when I change the syntax

It only gives me the error when I run it on the robot, and the brain’s screen gives an error.
here’s the not-functioning code in full:

#Tell the brain that this program is running so it can start the while loop at the bottom
run = True

#Pre-Run variables
driver = False
auto = False

def run_broadcast():
    brain.screen.print("Program Started!")
    print("Program Started!")

#These two detect when an alternating signal has been sent to the brain
#to change between autonomous and driver control.


competition = Competition(driver_control, autonomous)


if run == True:
    run_broadcast()
    wait(2, SECONDS)
    print("\033[2J")

def motorbrake():
    motor_FR.stop()
    motor_FL.stop()
    motor_BR.stop()
    motor_BL.stop()

def motorsettings():
    motor_FR.set_stopping(COAST)
    motor_FL.set_stopping(COAST)
    motor_BR.set_stopping(COAST)
    motor_BL.set_stopping(COAST)

def moveforward():
    motor_FR.spin(FORWARD)
    motor_BR.spin(FORWARD)
    motor_FL.spin(FORWARD)
    motor_BL.spin(FORWARD)

def controls():
    motor_FR.set_velocity(controller_1.axis3.position(),PERCENT)
    motor_BR.set_velocity(controller_1.axis3.position(),PERCENT)
    motor_FL.set_velocity(controller_1.axis2.position(),PERCENT)
    motor_BL.set_velocity(controller_1.axis2.position(),PERCENT)

motorsettings()


def driver_control():
    brain.screen.next_row()
    brain.screen.print("Driver control")
    controls()
    


def autonomous():
    brain.screen.next_row()
    brain.screen.print("Auto control")
    if distance_sense.object_distance(MM) <= 50:
        motorbrake()
    else:
        moveforward()

The error it gives me is:

Traceback (most recent call last):                       python exception ........
   File "userpy", line 38, in <module>
nameerror: name not defined

move this line to the end.

competition = Competition(driver_control, autonomous)

driver_control and autonomous must be defined before you call it.

4 Likes

Thank you, this fixed the problem!

1 Like