Skip to content

Add _onlyIf and _onStart preconditions (#820, #895) - #1261

Open
facontidavide wants to merge 1 commit into
masterfrom
feat/onstart-onlyif-preconditions
Open

facontidavide wants to merge 1 commit into
masterfrom
feat/onstart-onlyif-preconditions

Conversation

@facontidavide

Copy link
Copy Markdown
Collaborator

Closes #820 and #895. Supersedes #821 (@lukicdarkoo) and #932 (@Aglargil), who are credited as co-authors.

  • _onlyIf="<script>": if false when the node is IDLE, return SKIPPED (the opposite of _skipIf).
  • _onStart="<script>": run a script right before the first tick() of the node, only if no other precondition returned a status first.

Both are evaluated only when the node is IDLE/SKIPPED, like _skipIf. Evaluation order: _failureIf, _successIf, _skipIf, _while, _onlyIf, _onStart.

Compatibility

  • ONLY_IF and ON_START are appended at the end of PreCond (Add onlyIf precondition #821 inserted ONLY_IF in the middle, which changed the existing values). PreCond::COUNT_ and TreeNode::PreScripts get longer, but binaries built against the old headers only read the first four entries, which have not changed.
  • Appending ONLY_IF after WHILE_TRUE keeps the semantics: _skipIf, _while and _onlyIf all return SKIPPED, so their relative order doesn't matter.
  • Behavior change: _onlyIf and _onStart are now reserved attribute names. Before, they were stored silently as non-port attributes and did nothing.
  • Fixes a bug in Add onlyIf precondition #821: _skipIf stopped working unless _onlyIf was also present.

Also updated

XSD precondition group, docs/pre_postconditions.md, docs/name_validation_rules.md.

Tests

5 new tests in gtest_preconditions.cpp. They cover the order (_onStart runs after the checks and not when another precondition short-circuits), running once per execution (again after a halt), and _onlyIf vs _skipIf and _while. All 5 fail on master; 600/600 pass with this PR.

⚠️ Groot2 must support the two attributes before release.

🤖 Generated with Claude Code

- `_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>
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onlyIf Pre Condition

1 participant