View Single Post
  #4  
Old 10-02-2011, 06:08 PM
magicode's Avatar
magicode magicode is offline
Senior Member
VEX # 4542
 
Join Date: Sep 2010
Posts: 608
Re: RobotC programming tips

Structs are useful when doing more complex programming. For those who don't know what they are, 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:
Code:
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:
Code:
robotArm leftArm;
leftArm.maxPos = 2000;
leftArm.minPos = 150;
leftArm.armSpeed = 100;
__________________
It's not a bug, it's a feature.
Reply With Quote