Why would this even compile?

OK, helping the kids and I noticed this little slip up in the code and I’m wondering why it even compiled. The button is on one of the digital ports configured in the window, not via coded commands if that makes a difference. Back using RobotC v3.04 too.

Here’s the line of code in question:

while( SensorValue**(frontButton)** != 1)
{
//wait a bit… this code is not important to this post…
}

It should be:

while( SensorValue****frontButton**]** != 1)
{
//wait a bit… this code is not important to this post…
}

Why would SensorValue looking like a function reference versus an array offset even compile? It did not act the way we would have liked so that’s why we stumbled upon it.

I saw in some search that SenosorValue as a function from an NXT post but nothing for Vex Cortex that way.

Thanks!

This was something that we implemented a long time ago to make ROBOTC more beginner friendly. The compiler is pretty forgiving about this and some other things like capitalization rules. The compiler corrects things “behind the scenes” rather than causing the code to fail.

The thing is it’s not acting like the bracket version of SensorValue for us (why we found it in the first place). So the behind the scenes thing may no longer be working as originally implemented.

Can you go into more detail about “not working”? I tried the following code in ROBOTC 3.08 and it worked as expected.

task main()
{
  while(SensorValue(touch) != 1)
  {
    SensorValue[led] = 1;
    wait1Msec(1000);
    SensorValue[led] = 0;
    wait1Msec(1000);
  }
}