-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page about "trigger once" (#258)
- Loading branch information
Showing
6 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
docs/gdevelop5/all-features/advanced-conditions/trigger-once/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Trigger Once Condition | ||
--- | ||
# Trigger Once Condition | ||
|
||
When the "**Trigger once while true**" condition is used, the event actions are executed only once as long as the specified conditions are met. | ||
|
||
## Simulating the "Trigger Once" Condition with Variables | ||
|
||
The "trigger once" condition maintains a state that tracks whether the conditions above it were met in the previous frame. If the conditions are met: | ||
- If the conditions were **previously met**, the actions are **not triggered**. | ||
- If the conditions were **not previously met**, the actions are **triggered**. | ||
|
||
The following event... | ||
|
||
 | ||
|
||
...can be replicated using variables: | ||
|
||
 | ||
|
||
This example demonstrates how the "trigger once" condition functions. However, this is primarily to help understand its limitations, as explained in the next section. | ||
|
||
## Triggering Actions Once Per Object Instance | ||
|
||
The "trigger once" condition is **not evaluated per instance**. If at least one instance meets the conditions, the action will not be triggered for any other instances, even if they meet the conditions later. | ||
|
||
For example, if you want to play a "surprised" animation when the player gets close to an enemy, the "trigger once" condition may work if enemies are spaced far apart. However, if the player is already being chased by one enemy, other nearby enemies will not trigger the "surprised" animation. | ||
|
||
To handle this, you need to use [object variables](/gdevelop5/all-features/variables/object-variables/) to track the state of each object instance individually. While boolean variables can be used, string variables are often clearer, especially when objects have more than two possible states. | ||
|
||
 | ||
|
||
!!! info | ||
|
||
For a more detailed explanation, refer to the [finite state machines](/gdevelop5/tutorials/finite_state_machine) page. |
Binary file added
BIN
+33.9 KB
...gdevelop5/all-features/advanced-conditions/trigger-once/trigger-once-as-fsm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.3 KB
...op5/all-features/advanced-conditions/trigger-once/trigger-once-as-variables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.95 KB
...lop5/all-features/advanced-conditions/trigger-once/trigger-once-key-pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-35.1 KB
(89%)
docs/gdevelop5/events/js-code/javascript-in-extensions/extra-source-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.