Quote:
Originally Posted by Fifthparallel
It lies in the "new" keyword. The command you're instantiating is not a singleton, nor is it atomic. On that note, the WPILib function WhenPressed for a Joystick Button takes an argument for a command. You can insert new to make it create a new instance of that Command, i.e., the constructor for a new Command will run every time that button is pressed.
|
Uh... no, sorry, that's not how it works. If you look at the
documentation, you'll see the following line:
Code:
void WhenActive (Command *command)
That means the function receives a pointer pointing at a Command object. When you write:
The type you get from that expression is a pointer to a DoStuff object (the one you just created). If you can point me to any piece of code that suggests it somehow uses that object to create more objects of that kind, please do.
Looking deeper into the code, you can see that instance ends up being stored in an instance of "PressedButtonScheduler", which takes it upon itself to check the state of the button and
start the command instance if necessary (not create another instance).