Skip to content

[Custom extension] Fix no longer relevant explanations #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions docs/gdevelop5/behaviors/events-based-behaviors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ Behaviors are grouped into [extensions](/gdevelop5/extensions). They are the sam

Click on **Create or search for new extensions** at the bottom. Then, select **Create a new extension** to [create a new extension](/gdevelop5/extensions/create).

By default, extensions don't have any behavior. Add one by clicking on **Add a new behavior** on the left.
By default, extensions don't have any behavior. Add one by clicking on the "+" button on the left next to **Behaviors**.

![](pasted/20210906-234614.png)
![](/gdevelop5/events/functions/empty-extension.png)

You can choose the description and the name to display to users when they will add your behavior to an object. If you need to use a specific object (sprites, texts...), you can choose it with the drop-down list at the bottom.

Expand Down Expand Up @@ -142,14 +142,11 @@ Properties can also be used to required behaviors as described in a following se

### Use actions and conditions to manipulate the properties

Once you have created some properties on your behavior, conditions and actions will be automatically added in the events sheet. For each property, there will be a condition to compare its value, and an action for changing it.
Strings and numbers will also have an expression to get their values.
Number, string and boolean parameters can be used with the same actions and conditions as global and scene [variables](/gdevelop5/all-features/variables). Properties can also be used directly in expressions by writing their name. For instance, a property called "ScoreToMultiply" can be used the following: `2 * ScoreToMultiply`.

!!! note

If you rename your properties, the actions/conditions/expressions will be updated automatically.
Properties won't be usable from outside of the behavior. Properties are said to be "private", they can only be manipulated by the behavior. If you want to let extension users modifying them from the scene events, you can generate an action and a condition from the drop-down menu of the property.

These actions/conditions/expressions won't be usable from outside of the behavior. Properties are said to be "private", they can only be manipulated by the behavior. If you want to let extension user modifying them from the scene events, you can generate an action and a condition from the drop-down menu of the property.
![](generate-property-accessors.png)

## Behaviors using other behaviors as properties

Expand All @@ -164,6 +161,18 @@ If you create a behavior and want to use this, just go to the properties of this

To use a behavior based on another, you don't need to do anything special! Just add it to your object as usual: any missing behavior will be added to your object, so you can start using it immediately.

## Write behaviors dedicated to your project

You probably used extensions from the community. These extensions aim to be usable in many projects, but extensions can also be created with only one project in mind.

The [platformer template](https://gdevelop.io/game-example/free/platformer) has a `Enemy` extension with a `MonsterEnemy` behavior. This behavior toggle between
- a **Fire** state where it hurts the player
- a **NoFire** state where the player can jump on it

![](platformer-enemy-extension.png)

The [Bomberman-like template](https://gdevelop.io/game-example/free/3d-bomber-bunny) shows how a game can be organized into extensions. The players, bombs and bonuses have their own custom behavior. It allows to gather the logic of each object in one place: their extension. The main events can then focus on how these objects interact with each other.

## A word about the advantages of behaviors

Creating your own behaviors has multiple advantages:
Expand All @@ -178,6 +187,11 @@ Creating your own behaviors has multiple advantages:

## Examples/ideas for custom behaviors

Installing and opening existing extensions can be a good way to see how behaviors work. The following extensions are simple enough not to feel lost when looking at their events:

- [Animated back and forth movement](https://wiki.gdevelop.io/gdevelop5/extensions/animated-back-and-forth-movement/)
- [Flash object](https://wiki.gdevelop.io/gdevelop5/extensions/flash/)

You can imagine tons of different behaviors. Here are a few examples:

* A behavior to **manage the health of an enemy or a boss**.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 22 additions & 9 deletions docs/gdevelop5/events/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Functions are grouped into [extensions](/gdevelop5/extensions). They are the sam

Click on **Create or search for new extensions** at the bottom. Then, select **Create a new extension** to [create a new extension](/gdevelop5/extensions/create).

By default, extensions don't have any function. Add one by clicking on **Add a new function** on the left.
By default, extensions don't have any function. Add one by clicking on the "+" button on the left next to **Functions**.

![](pasted/20221118-093435.png)
![](empty-extension.png)

A new function is added, it's time to give it a name. By convention:

Expand Down Expand Up @@ -79,9 +79,11 @@ Conditions and actions from behaviors can also be used in functions events. For

#### Use parameter values

A number, string and boolean parameter values can be compared with conditions.
Number, string and boolean parameters can be compared with the same conditions as global and scene [variables](/gdevelop5/all-features/variables).

![](functionn-parameter-condition.png)
!!! note

Parameter values can't be changed with actions. If you want to give back a value to scene events, you have to create a [custom expression](#return-a-value-from-a-function).

Parameters can also be used directly in expressions by writing their name. For instance, a parameter called "ScoreToMultiply" can be used the following: `2 * ScoreToMultiply`.

Expand Down Expand Up @@ -109,19 +111,30 @@ Function that are conditions or expressions must return a value. The returned va

### Use variables from function events

Variable can be useful within functions for intermediary results or to keep a state in the extension.
From function events, expressions must be used to access variable values:
Variables can be useful within functions for intermediary results or to keep a state in the extension. You can declare new [variables](/gdevelop5/all-features/variables) that are accessible only inside the extension by clicking on **Extension global variables** or **Extension scene variables**.

- `GlobalVariable(MyVariable)` for global variables
- `Variable(MyVariable)` for scene variables
- `MyObject.Variable(MyVariable)` for object variables
!!! tip

If you feel the need to modify object variables, there is a good chance that you should rather make a [custom behavior](/gdevelop5/behaviors/events-based-behaviors/) and use properties.

## Use functions in events

Extension functions can be found in conditions and actions lists like any other feature of the engine.

![](pasted/20221118-094110.png)

## Write functions dedicated to your project

You probably used extensions from the community. These extensions aim to be usable in many projects, but extensions can also be created with only one project in mind.

The [platformer template](https://gdevelop.io/game-example/free/platformer) has a `Player` extension with a few functions. For instance, the function `AnimateFallingIntoPortal` uses a few actions to make an animation that is played at the end of the level.

![](platformer-player-extension.png)

Visual and sound effects can quickly take a lot of space. Making small functions like this allow to keep the scene events easy to follow.

![](platformer-player-extension-usage.png)

## Advanced usages

This page gave a basic overview of what functions are. They are one of the more powerful features of GDevelop, as you can extend the events by using them, enabling to create very readable and concise events sheets. By using them, you can reduce the amounts of events that you write for your game, avoid copy-pasting them and even reduce bugs by ensuring that functions are always used for common tasks on your objects.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.