Closed GregoryLi360 closed 6 months ago
Calling isFinished
after end
is undefined behavior. What are you trying to do?
I’m not sure why that would be undefined behavior.
I am trying to create an inner SequentialCommandGroup that will execute when the outer command computes a value that needs to use the periodic game loop. When the inner SequentialCommandGroup ends, I want the outer command to also end.
Why can't you have them composed (possibly by proxy if you understand the implications of proxying) or merged?
It's undefined because the state of a command object is defined and valid only while it is running, meaning between initialize
and end
.
I wanted the outer and inner structure so that the computed value will be contained within the scope of one simple outer command while the inner SequentialCommandGroup is a composition of reusable components.
At the core, I think SequentialCommandGroup.isFinished() not being true is causing our auto sequence to stop at that specific command.
You shouldn't be calling isFinished
directly.
I wanted the outer and inner structure so that the computed value will be contained within the scope of one simple outer command while the inner SequentialCommandGroup is a composition of reusable components.
Why can't the two be composed in a sequence?
In that case would I have to pass a setter function into the first command?
I also expected the isFinished() function to be useful for determining if a command sequence has finished. The documentation for the function is misleading. It says that the return value for this public function indicates whether the command has finished. It is a just a wrapper function for the value false and worse leads to undefined behavior?
The documentation is intended so teams know how to implement it -- it is not intended to be called by team code!
Team code shouldn't be holding references to commands at all, imo, and definitely not calling internal lifecycle methods on them. The C++ ownership semantics do this the right way.
If you want to do something when a sequence (or any other command) ends, there are several ways to do this without undefined behavior:
finallyDo
/handleInterrupt
(for lambdas)
Describe the bug SequentialCommandGroup.isFinished() does not return true when all commands in the command group are finished.
To Reproduce Steps to reproduce the behavior:
Check if the SequentialCommandGroup is finished when all commands in it are finished
kA.onTrue(new InstantCommand(() -> { System.out.println("command group finished: " + commandGroup.isFinished()); }));