Program aborts when Autonomous starts

I made an auton selector for my program and it compiles fine and works great in driver control when choosing what program I want it to perform, but the program aborts once autonomous is enabled. The error occurs on line 43 and spits out:

EXCEPTION: 0xEA Name error
FILE_ID 0x09 / Line 1756
File “main”, line 43, in autonomous

The link to my code is: https://www.robotmesh.com/studio/5d6eace48055570c7b79bada

Some guidance would be appreciated!

Your first assignment to BlueLeft (and several other variables) is in the local scope of pre_auton. There is a global keyword in Python that specifies whether you will be referring to the global variable with a particular name instead of a local one, so you could add a line like this at the start of pre_auton to show that it’s going to be referring to them in the global scope:

def pre_auton():
    global global_var_1, global_var_2 #[etc etc]
    #rest of function
2 Likes

Ok I tried that and it seems to have fixed the issue with the program aborting or giving the error, but it still wont run anything during autonomous period.
It seems that issue could be that even if I press the area needed to run that command, it still wont set the var BlueLeft to 1 because I tried putting commands outside of the if statement during auton and it ran that command. So it is running through autonomous but it doesn’t find anything True.

Thanks for helping me out by the way, this thing has been bugging me for days. This might be the last help I need lol.

NEVERMIND I GOT IT FIGURED OUT! I just added the global variable list to pre-auton, autonomous, and drivercontrol and it seems to have fixed it :slight_smile: