Skip to content

Add _onStart precondition for script execution and fix CI error - #932

Closed
Aglargil wants to merge 3 commits into
BehaviorTree:masterfrom
Aglargil:master
Closed

Aglargil wants to merge 3 commits into
BehaviorTree:masterfrom
Aglargil:master

Conversation

@Aglargil

@Aglargil Aglargil commented Feb 10, 2025 •

Copy link
Copy Markdown
Contributor

#895

  1. feat: add _onStart precondition for script execution
  2. fix covert_impl checkTruncation for CI error

Add a new precondition type _onStart that allows executing scripts
before a node starts its tick. This provides symmetry with the
existing _post functionality.
@Aglargil

Copy link
Copy Markdown
Contributor Author

Hi, @facontidavide
I've implemented the fixes in the PR, including adding the _onStart precondition and resolving the CI error in covert_impl checkTruncation. If you'd prefer a separate PR for just the CI fix, feel free to let me know—I'm happy to adjust!

@facontidavide

Copy link
Copy Markdown
Collaborator

@Aglargil I do want to include this, but I can not until I add this precondition to Groot2. Be patient :)

@facontidavide facontidavide self-assigned this Feb 25, 2025
@facontidavide facontidavide added the enhancement New feature or request label Feb 25, 2025
@Aglargil

Copy link
Copy Markdown
Contributor Author

@Aglargil I do want to include this, but I can not until I add this precondition to Groot2. Be patient :)

Okay, looking forward to your updates!

@facontidavide

Copy link
Copy Markdown
Collaborator

Thanks @Aglargil, and sorry for the long wait! Superseded by #1261, which adds _onStart (with you as co-author) together with _onlyIf. It follows your approach: ON_START is the last precondition, so the script only runs if the node is actually going to tick. The checkTruncation CI fix is no longer needed on master.

facontidavide added a commit that referenced this pull request Nov 7, 2026
* Add _onlyIf and _onStart preconditions (#820, #895)

- `_onlyIf="<script>"`: if false when the node is IDLE, return SKIPPED
  (the opposite of `_skipIf`, more readable in most cases).
- `_onStart="<script>"`: execute a script right before the first tick() of
  the node, i.e. only if no other precondition returned a status. Useful
  to initialize or reset blackboard entries.

Both are evaluated only when the node is IDLE/SKIPPED, like `_skipIf`.

ONLY_IF and ON_START are appended at the end of PreCond, so the values of
the existing ones don't change. Appending ONLY_IF after WHILE_TRUE keeps
the semantics: SKIP_IF, WHILE_TRUE and ONLY_IF all return SKIPPED.

Behavior change: the attribute names `_onlyIf` and `_onStart` are now
reserved. Before, they were stored silently as non-port attributes and
did nothing.

Supersedes #821 and #932.

Co-Authored-By: Darko Lukic <2135826+lukicdarkoo@users.noreply.github.com>
Co-Authored-By: Aglargil <34728006+Aglargil@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Preconditions: static_assert on name arrays, fix _onStart comment, document _onStart/_onlyIf caveats

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover _onlyIf/_onStart edge cases (while-interrupt, SubTree, ReactiveSequence, WriteTreeToXML)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Darko Lukic <2135826+lukicdarkoo@users.noreply.github.com>
Co-authored-by: Aglargil <34728006+Aglargil@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BT.CPP-5 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants