Logical Error with Side Thrusters

Hello,

If you have

if A
else if D
else stop both thrusters

I feel that this could create an error where if the player…

  • holds A
  • holds D
  • release A

Both side thrusters would be active at the same time.
Let me know if my logic is wrong!
I did test the code and I don’t think I noticed both side thrusters to be on at the same time but logically speaking it would make sense to me if they were.

Ben

Hi Ben,

I have two questions for you:

  • What is the difference between if and else if?
  • When/how do your conditions (if A, else if D, else stop) get evaluated?

If you are able to answer these questions, you also know whether you discovered a ‘logical error’. The computer follows a strict logic. We have to adjust our own logic to it, not the other way round, so knowing how C# works in this case is crucial.

Hello Nina, thank you taking the time to write me some instructions.

If, else if and else sequences are checked in order.
First, the software will check if the “if” statement is “true”; if it is, it will action the code block and it will ignore any subsequent “else if” and “else” related to the “if” statement.

If the first “if” statement is false, it will check all subsequent “else if” in the same manner. If all “if” and “else if” statements are “false”, then it will action whatever is in the code block of the “else” section.

That is the way I always thought it worked out as. My main language was Java, I wonder if there is a difference between Java and C# or if my understanding was always lacking.

Please let me know if there is anything that I got wrong because from my point of view, if I held A (which would turn on particles for A counter side) and then held D at the same time, give that A is the superior statement, the particles for D should to trigger.

And then if I release A while still holding D; the particles for D counter side should trigger but the A particles should still be turned on because the “else” section was never reached.

Yeah, I think you’re quite right.
When you hold A (left), the right thruster starts (the opposite thruster). Now holding D (right) would do nothing because the if would still execute for A being held. When you let go of A, it would start the right thruster (else if) and start rotating left (because D is pressed now) but it would only stop rotating right (because A is no longer pressed) but the particles will still continue to play because - like you said - nothing is stopping the particles. The particles only stops when no buttons are pressed

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

Privacy & Terms