I am trying to take a variable from the pre_auton void to the autonomous void. However, it won’t let me return the variable. Is there a way to take a value from a variable from the pre_auton void and use it for the autonomous void?
Declare it ahead of time, not inside of pre_auton. If you declare a variable inside a function, it’s local to that function and not accessible from elsewhere. So declaring it at a broader scope will let you still change it inside pre_auton and then access it later.
The pre_auton determines the value of the variable so I can’t declare it ahead of time
Declare the variable outside of pre_auton and then set it in pre_auton.
float variable1 = 0
variable1 = 1
You can use global variables inside functions, too. Or maybe you’re confused between declaring it and setting it. Do what @Adam and I are telling you. Declare it ahead outside of and before pre_auton and then set it within pre_auton. It will work.
So for example, I declare the variable “x” as 1 ahead of the pre_auton. Then, inside the pre_auton, x changes to 1. Will x be 1 during the regular autonomous?
Correct. It will also be one during opcontrol if it isnt changed in autonomous.