Help With Multiple Autonomous Codes

Right now our code looks like this:


The autonomous starts when we press a button.
We want it so when the judges start autonomous, the code we pressed when the brain started would run.
How do you do this?

It’s the referees and/or TM Manager that starts autonomous. Judges are the guys who make sure that your logbook follows a design process and interviews you.

Anyways, I’m not experienced with VEXCode Blocks, but the way your code is set up, it would run the drive once the button is pressed. The reason why you were told to set up each button with a variable was to reference within autonomous. The pseudo code would be something akin to

when program started{
draw all buttons
set all variables to false
while (all variables are false){
if a button is pressed, set one variable to true}
end set of code}

Then, there would probably be another flag

when autonomous started{
If(variable 1 is true) {run auton 1}
else if (variable 2 is true) {run auton 2}
else if (variable 3 is true) {run auton 3}
end code}

You need a flag that checks for when autonomous starts, and references the variables initialized, instead of putting the drive and turn functions within your setup. I don’t want to give you the code outright so you learn, but I’m willing to help once you understand my suggestion.

3 Likes

I can’t find the if(variable is true) block. But then again, I suck at finding stuff.

No problem! It’s always hard learning for the very first time. You would use an IF statement, and also the lime green operator that checks if two things are equal. Then, you would put the variable (which should be an orange oval) on one side, and probably type in true for the other. this isn’t the most efficient way to do it

so you make a variable named true?

No, the variable can be named anything, in Blocks you would make a boolean, which has a value of either “true” or “false”. In this case you begin it on true.

2 Likes

oops I get it. You TYPE in true.
EDIT: oops, you can’t type

No, no. You just don’t have to put a boolean in an operator. It’s good by itself and will return a 0 or 1.

2 Likes

(picture deleted to stop confusing people)
I… did you delete your previous post? But yes, what Josh said was right.

when I try to make a variable it says “name already taken”

Yeah, listen to josh and put the pointy variable directly into the if statement. Ignore everything I said after I said “No Problem”.

sorry, I’m confused @2775Josh can you take a pic?

image

2 Likes

It automatically be like “if block1=true then…”? or does it just run anyway?

help2

I think this is what you are asking?


would it run Red4 only if Red4 is true, or would it run Red4 anyway even if it’s false?

It would run red4 as long as red4 is true and block1 and block4 are both false. If you want these to be independent of each other, don’t use else statements.

then what would I use? The code in each else statement is a seperate auton.

Just don’t use else statements; put each if statement under one another but not nested. If they’re separate autons then what you have should work though.

5 Likes

So change or no change?