We just successfully tested a recordable auton that uses arrays onto our classroom squarebot and are looking to transfer the algorithm onto our competition bot. However, we are worried that when the competition template switches from driver to auton, it clears integers, which would ruin our auton. Does anyone know if this is true?
It’s difficult to answer your question briefly, or without sounding like a programming snob. I’m not trying to demean your knowledge; asking questions is how we all learn. I’ll try to be brief, but if you’ve read any of my posts, you know I can’t really do that. And I can’t avoid saying “hypothetical” sometimes, either.
Between autonomous and drive tasks, nothing is really “cleared,” however variables not in scope are just that: not in scope. Which means they can’t be seen. The fact that they are integer (“int”) type has nothing to do with it.
If you declare a variable inside a set of curly braces, whether those braces are the highest level ones of a task, or inside a while loop, or in one branch of an if statement, then no code outside those curly braces can see the variables. You can also cover up an existing variable by declaring a new instance of the same name inside an internal block of code demarked by curly braces. The outer scoped variable still exists, but the code inside the inner block can’t see it.
A practical answer:
You have two easy choices:
- Declare variables you want to be seen in multiple scopes in the source file outside of any block of code. Right after the pragmas, for instance. These are global variables, and will be visible in every inner scope. (Unless the name is “covered” in the inner scope by a new definition using the same name. Don’t do that and you’re fine.)
- Create a function that you can call from within any task or function. (Function names in C exist in a global scope.) Inside your function, declare the variables that contain your recorded autonomous routine. Call the function whenever you want to use the recorded values.
I don’t have much experience in the realm of recordable autonomous but one our teams tried using a recordable autonomous and what he did was have the autonomous be recorded in a separate code file and then he just transferred it into his competition template.
The easiest solution I can think of is just declare the variables at global scope level. If you must alter the values I believe you could preset the values of the variables within the task.
I don’t think you understand the question: We’ve already tested the recordable auton, and our variables are already global, we just wanted to make certain the comp template doesn’t clear ints when it goes from driver control to autonomous mode.
It does not clear any variables.
Test it? I don’t see how this is complicated. A better question would be how to fix it if it doesen’t work