Difference between revisions of "Using Structs"

From ROBOTC API Guide
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE: Using Structs}} <yambe:breadcrumb self="Using Structs">Programming_Tips_Tricks|Programming Tips Tricks</yambe:breadcrumb> <br /> Structs are variables made of...")
 
(No difference)

Latest revision as of 20:27, 15 May 2012


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.