When i start the code it goes back to the play screen

When I start the code it immediately goes back to the program screen. I know the fault is in driver program because before i added parts of code from controller express into the driver program it worked. I am using robot mesh.
these are the parts I added

    motor_left_power = 0
    motor_right_power = 0

    move = joystick.axis1()
    steer = joystick.axis3()
    if move != 0 cor steer != 0:
        motor_right_power = move - steer
    if move != 0 or steer != 0:
        motor_left_power = move + steer
    motor_right.spin(vex.DirectionType.FWD, motor_right_power)
    motor_left.spin(vex.DirectionType.FWD, motor_right_power)

this is the full code

import vex
import sys

#region config
brain       = vex.Brain()
motor_right = vex.Motor(vex.Ports.PORT15, vex.GearSetting.RATIO18_1, False)
motor_left  = vex.Motor(vex.Ports.PORT16, vex.GearSetting.RATIO18_1, True)
dt          = vex.Drivetrain(motor_left, motor_right, 319.1764, 292.1, vex.DistanceUnits.MM)
con         = vex.Controller(vex.ControllerType.PRIMARY)
#endregion config

competition = vex.Competition()

def driver():
  # Place drive control code here, inside the loop
  while True:
    motor_left_power = 0
    motor_right_power = 0
    # This is the main loop for the driver control.
    # Each time through the loop you should update motor
    # movements based on input from the controller.
    #motor_left.spin(vex.DirectionType.FWD, (con.axis3.position(vex.PercentUnits.PCT)), vex.VelocityUnits.PCT)
    #motor_right.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)), vex.VelocityUnits.PCT)
    move = joystick.axis1()
    steer = joystick.axis3()
    if move != 0 cor steer != 0:
        motor_right_power = move - steer
    if move != 0 or steer != 0:
        motor_left_power = move + steer
    
    motor_right.spin(vex.DirectionType.FWD, motor_right_power)
    motor_left.spin(vex.DirectionType.FWD, motor_right_power)    
competition.drivercontrol(driver)

def auto():
  # Place autonomous code here
  dt.drive_for(vex.DirectionType.FWD, 24, vex.DistanceUnits.IN)
  dt.turn_for(vex.TurnType.LEFT, 180, vex.RotationUnits.DEG)
  dt.drive_for(vex.DirectionType.FWD, 24, vex.DistanceUnits.IN)
  dt.turn_for(vex.TurnType.LEFT, 180, vex.RotationUnits.DEG)
competition.autonomous(auto)


# main thread
# All activities that occur before competition start
# Example: setting initial positions
con.set_deadband(5, vex.PercentUnits.PCT)
dt.set_velocity(20, vex.VelocityUnits.PCT)

You have no token called joystick. You called your handheld controller con on this line:

You are getting a name error. If you run your program from the editor with the programming cable still attached to the robot, it will feed those errors to you in the console at the bottom of the editor in big angry red letters and tell you which line it encountered the error on.

There’s one other problem that I can see, too:

    if move != 0 cor steer != 0:
        motor_right_power = move - steer
    if move != 0 or steer != 0:
        motor_left_power = move + steer

Has one problem and one thing that could be done better. The problem is you typo’d and wrote cor instead of or on the first if. The thing that could be done better is just eliminate the second if entirely and include its contents in the first if, as it’s no different than the first.

1 Like

Would i just change joystick to con so it would be con.axis1()?

i changed it and now my code works but i cant turn…

Same problem on the next line:

Again, joystick should be changed to con.

Ah, sorry, nope. I didn’t keep reading that line far enough. axis1 is an attribute of a controller, not a method. The methods are on the axes themselves. So it would be con.axis1.position().

Controller class

ControllerAxis class

i already fixed that but i had axis 1 as move and 3 as steer. I fixed it. Thanks for the help!