I would like to be able to Pause the current task, while keeping the CC response active. An example would be, while running GB2, after harvest, I'd like a plugin to complete an action without being interrupted. What (safe) methods do I have ... ?
I believe you've got conflicting requirements. As I understand it, Honorbuddy (at a 10000 foot level), behaves similar to the following:
Code:
while (true)
{
1. tick the behavior tree
2. pulse each of the plugins
}
If this is a correct understanding of Honorbuddy internals, then you've got a problem:
- In order for the CC to remain responsive, you must return (quickly) from the plugin Pulse() to allow the behavior tree to 'tick'
- To guarantee your action cannot be interrupted, you must not return from the plugin Pulse() until your desired action completes
This is one of the many reasons why 'sleep' inside plugins or CCs is simply evil. It prevents Honorbuddy from doing
anything else until the sleep completes. The TreeSharp
Wait action is an excellent alternative to sleep that does not have these limitations. Alas, the
Wait action cannot be used in a plugin, unless you're willing to provide your own tree walking routine for the plugin. (I.e., your willing to implement and execute your plugin as a BT. But, this would be a distinct BT from that used by Honorbuddy.)
Your only real alternative is to build your plugin's Pulse as a state machine, and return as quick as you can. The state machine would have to 'recover' to the desired state if the BT or another plugin messed up the current state it was in.
You can also play games with threads as Jim87 suggested, but this is
very dicey. As, Honorbuddy was not architected to facilitate this. Multi-threading plugins/CCs
can be done, but it is a frequent source of errors, and a pain to debug--even for those that are very good at it.
If you provide more details about what you're trying to accomplish, perhaps the Community can supply you with a more solid answer as to your viable solution space.
cheers & good luck with it,
chinajade