Quote:
Originally Posted by buckskinner1776
This command seems to execute with the initial 10" instead of the 100".
|
Lacking source code, both Gus and Pault's theories could easily be true. They're both theories about scoping and order of evaluation.
As an aside, I think Pault's criticism of the CommandGroup is more about the subtleties of Java's pass-by-value semantics. A statement like:
Code:
addSequestial(new Command2(Robot.drivedistance));
means "create a command with the current value of Robot.drivedistance". At the point the JVM news up a Command2, it takes whatever the value is of Robot.drivedistance, and passes it in as a parameter.
Here is an easy way to use CommandGroups to achieve what Pault is desiring, without a lot of extra code.
Suppose you have two Commands, CalculateDistanceToShootingPosition and DriveForward. You want to execute them in sequence in a CommandGroup. You could say something like this in the CommandGroup's constructor:
Code:
DriveForward df = new DriveForward();
CalculateDistanceToShootingPosition calc =
new CalculateDistanceToShootingPosition(df);
addSequential(calc);
addSequential(df);
Now, suppose that DriveForward has a method SetDistanceToDriveInInches(). In CalculateDistanceToShootingPosition.Execute(), you'd do the calculation and then call SetDistanceToDriveInInches(). Later, when DriveForward runs, it has the correct value to drive to. This uses the correct value, and eliminates a global variable, making DriveForward more flexible and easier to reason about.