Quote:
Originally Posted by notmattlythgoe
I haven't looked at the wait command under the hood, but this is how I believe it works. I can look under the hood tonight at the source code and see if I'm correct.
Code:
public class WaitCommand extends Command {
private double waitTime;
public WaitCommand(double waitTime) {
this.waitTime = waitTime;
}
public boolean isFinished() {
return timeSinceInitialized >= waitTme;
}
}
|
I don't read much Java code. Is this the correct interpretation of what that code is supposed to do?
- the first time it is executed it notes the system time so that it can compute the value of "timeSinceInitialized" each time it is executed.
- it gets executed every 20ms as long as it returns "isFinished()" as false
- it returns "isFinished()" as false as long as "timeSinceInitialized" is less than the desired "waitTime" that was passed as a parameter
- as long as it is returning "isFinished()" as false, any commands that are waiting for it to finish will not execute.
- when "timeSinceInitialized" is greater than or equal to the desired "waitTime", it returns "isFinished()" as true, which results in it being removed from the list of commands to be executed every 20ms. Any commands that were waiting for it to finish will now execute.