-1

I have been programming for some time in Python, and JavaScript. I have also programmed with the arduino language which is a mix between C and C++. I was just introduced to RobotC. The syntax used for RobotC is not like any language I have learned. Can someone help explain these syntax differences so I can better understand it?

Problem 1:

When making a motor turn, you can use the following syntax:

motor[motorA] = 50

What did that line just do? In any other programming language that is how you would change a value in an array, but in RobotC it acts like a function call. Is 'motor' an array, or an object? And why do I need a function when controlling servos?

Problem 2:

When in the history of programming is this allowed?

motor[leftMotor] = motor[rightMotor] = speed = 127;

And what which of the following would this code do?

speed = 127;
motor[rightMotor] = speed;
motor[leftMotor] = motor[rightMotor];

or

speed = 127;
motor[rightMotor] = 127;
motor[leftMotor] = 127;
Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
cweb
  • 382
  • 2
  • 11
  • 5
    This is a request for a RobotC book. At _best_, it's like four questions in one, which is also not allowed. – Lightness Races in Orbit Mar 11 '15 at 18:30
  • I can't find much about RobotC online, and it would make more sense if I could apply what I know from other programming languages to RobotC. – cweb Mar 11 '15 at 18:36
  • There's nothing special about that framework, there's no such thing like a _"mix between C and C++"_. It's a ll just plain C++ code, maybe using some C .APIs. – πάντα ῥεῖ Mar 11 '15 at 18:40
  • Strange. Googling 'RobotC' gave: 'about 396,000 results'. – Martin James Mar 11 '15 at 18:45
  • 2
    To understand Problem 1, you need to find the definition of `motor`. If that doesn't clear things up for you, then you'll need to add the definition of `motor` to the question. All three snippets in #2 do the same thing, and the first snippet has been allowed since C was originally developed, which would be around 1970. – user3386109 Mar 11 '15 at 18:48
  • Can you please make clear what is RobitC? From your question it sounds like it is a language. From comments it seems like it is a framework. I mean you are using it, so at least this you should know :P – 463035818_is_not_an_ai Mar 11 '15 at 18:50
  • well, I googled it myself and according to their homepage it is a C-based programming language. Please do not tag C++ unrelated questions as C++ – 463035818_is_not_an_ai Mar 11 '15 at 18:55

2 Answers2

5

1) You are setting the value of the item in array motor at index motorA to be equal to 50.

2) Multiple in-line assignments are evaluated from right to left, so this is the same as

speed = 127;
motor[rightMotor] = speed;
motor[leftMotor] = motor[rightMotor];
rageandqq
  • 2,221
  • 18
  • 24
0

RobotC takes many of its syntax logic from Java. Assuming motorA has been connected in the motor set-up than the motor can be told to move in this way.

motor[motorA] = 50;

essentially your experience on other code languages is correct and as you are calling and array. You are telling the program that in the array 'motor' at index 'motorA' set the value to '50'. since the 'motorA' index in linked to the actual motor than is can use the given value to know how to power the motor.

Brad
  • 9
  • 1
  • RobotC takes its syntax from C - hence the name. Java is an Object-Oriented language, that also happens to use C/C++ syntax, and is somewhat based on C++; but RobotC certainly is not based on Java. – CoolBots Nov 03 '16 at 07:46
  • Also, you can set a value in an array, or read a value from an array; you can't *call* an array, it's not a function. – CoolBots Nov 03 '16 at 07:48