Quote:
Originally Posted by Stonemotmot
Say I named a solenoid object 1 and had a int variable named b that stored 1 could i say
b.Set(true) and have the same result as 1.Set(True)
|
Many people are answering your question, but no one has asked why you want to do this. Generally numbers are a poor way to refer to things. Especially if the numbers are arbitrary (don't have any meaning in the mechanism you are controlling).
The best generic way to do this is to simply name variables or pointers for each mechanism and use those to refer to the solenoids or anything else.
Such as:
Code:
Solenoid *leftGripper = new Solenoid(2);
Solenoid *impaler = new Solenoid(3);
impaler->Set(true);
or
Code:
class MyRobot : public IterativeRobot
{
...
Solenoid leftGripper;
Solenoid impaler;
...
MyRobot() :
leftGripper(2),
impaler(3)
{
}
...
void AutonomousInit(void)
{
impaler.Set(true);
}
...
};
Do you have some compelling reason not to refer to each object directly?