Pre_Auton variables to Autonomous

  1. 2 weeks ago

    .4495c.

    Jan 4 4495C

    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?

    Correct. It will also be one during opcontrol if it isnt changed in autonomous.

  2. callen

    Jan 4 Braintree, MA, USA
    Edited 2 weeks ago by callen

    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.

  3. .4495c.

    Jan 4 4495C
    Edited 2 weeks ago by .4495c.

    The pre_auton determines the value of the variable so I can't declare it ahead of time

  4. Declare the variable outside of pre_auton and then set it in pre_auton.

    For example:
    float variable1 = 0

    preauton
    {
    variable1 = 1
    }

  5. callen

    Jan 4 Braintree, MA, USA

    @.4495c. The pre_auton determines the value of the variable so I can't declare it ahead of time

    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.

  6. .4495c.

    Jan 4 4495C

    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?

  7. Correct. It will also be one during opcontrol if it isnt changed in autonomous.

 

or Sign Up to reply!