Using Structs

From ROBOTC API Guide
Revision as of 20:27, 15 May 2012 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Structs are variables made of a collection of other variables. Again, this is not unique to ROBOTC, but still useful in general, and not as widely known to beginning programmers. I'll demonstrate with an example:

typedef struct{
  int maxPos;
  int minPos;
  int armSpeed;
  int prevSensorValues[10];
} robotArm;

This is an example of a struct. If you have multiple arms on your robot, you can have a struct to hold the properties of each one.

A struct is implemented, and its components are accessed like this:

robotArm leftArm;
leftArm.maxPos = 2000;
leftArm.minPos = 150;
leftArm.armSpeed = 100;

This tip was posted by magicode over at http://www.vexforum.com/showpost.php?p=220816&postcount=4.