The difference between "When controller" and "if / then"?

I’m not a programmer or really even a techy person. I’m more the mechanical and project management side. But I am trying to learn to be able then teach my team . Anyways, as I was playing around, I see I can choose something like
“When Controller Button E Up is Pressed Spin Motor Forward 90 degrees”
OR
I can choose “If Controller Button E Up is Pressed Then Spin Motor Forward 90 degrees”.

Also, we are using IQ Blocks if it makes a difference

What’s the difference? TIA

The If statement is likely under a ‘When Started’. It will only evaluate the first time it passes through unless it is inside a forever loop. You can only have 3 ‘When started’ tabs on vexcode.

The When Pressed is a better option because it is it’s own heading and will constantly evaluate.

1 Like

One is an event and the other evaluates a condition at a given time in the program. The event will trigger whenever the button is pressed which means it’s quick and easy, but harder to have situations where a button does something and other situations where it doesn’t.

The If statement evaluates one or more conditions at a given point in a program.

1 Like

I’m still not sure I understand the distinction, but I appreciate you taking the time to answer.

In the example files in VexIQ Blocks there is an example that shows how to use both to, for example, more an arm motor up and down. Is one option better than the other for that?

My students have an autonomous program that is great about scoring the green block on the low platform.
The also have a reliable driver program that uses IF statements to control their 4 Bar (L Up and L DOWN) and their Elevator (R Up and R DOWN).

They want to incorporate the automated scoring of the green cube into their driver program. They want to press a button on the controller (e.g. E Up) at the start of the match and have it run several lines of code. The tried adding a IF Block that does that, but then the L UP and DOWN and R UP and DOWN didn’t seem to work any more.

Is WHEN or IF better in this case?

(Once I get the code form them I can post it, but don’t have it right now)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.