You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/gdevelop5/behaviors/events-based-behaviors/index.md
+22-8Lines changed: 22 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -31,9 +31,9 @@ Behaviors are grouped into [extensions](/gdevelop5/extensions). They are the sam
31
31
32
32
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).
33
33
34
-
By default, extensions don't have any behavior. Add one by clicking on **Add a new behavior**on the left.
34
+
By default, extensions don't have any behavior. Add one by clicking on the "+" button on the left next to **Behaviors**.
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.
39
39
@@ -142,14 +142,11 @@ Properties can also be used to required behaviors as described in a following se
142
142
143
143
### Use actions and conditions to manipulate the properties
144
144
145
-
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.
146
-
Strings and numbers will also have an expression to get their values.
145
+
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`.
147
146
148
-
!!! note
149
-
150
-
If you rename your properties, the actions/conditions/expressions will be updated automatically.
147
+
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.
151
148
152
-
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.
149
+

153
150
154
151
## Behaviors using other behaviors as properties
155
152
@@ -164,6 +161,18 @@ If you create a behavior and want to use this, just go to the properties of this
164
161
165
162
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.
166
163
164
+
## Write behaviors dedicated to your project
165
+
166
+
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.
167
+
168
+
The [platformer template](https://gdevelop.io/game-example/free/platformer) has a `Enemy` extension with a `MonsterEnemy` behavior. This behavior toggle between
169
+
- a **Fire** state where it hurts the player
170
+
- a **NoFire** state where the player can jump on it
171
+
172
+

173
+
174
+
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.
175
+
167
176
## A word about the advantages of behaviors
168
177
169
178
Creating your own behaviors has multiple advantages:
@@ -178,6 +187,11 @@ Creating your own behaviors has multiple advantages:
178
187
179
188
## Examples/ideas for custom behaviors
180
189
190
+
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:
191
+
192
+
-[Animated back and forth movement](https://wiki.gdevelop.io/gdevelop5/extensions/animated-back-and-forth-movement/)
Copy file name to clipboardExpand all lines: docs/gdevelop5/events/functions/index.md
+22-9Lines changed: 22 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ Functions are grouped into [extensions](/gdevelop5/extensions). They are the sam
25
25
26
26
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).
27
27
28
-
By default, extensions don't have any function. Add one by clicking on **Add a new function**on the left.
28
+
By default, extensions don't have any function. Add one by clicking on the "+" button on the left next to **Functions**.
29
29
30
-

30
+

31
31
32
32
A new function is added, it's time to give it a name. By convention:
33
33
@@ -79,9 +79,11 @@ Conditions and actions from behaviors can also be used in functions events. For
79
79
80
80
#### Use parameter values
81
81
82
-
A number, string and boolean parameter values can be compared with conditions.
82
+
Number, string and boolean parameters can be compared with the same conditions as global and scene [variables](/gdevelop5/all-features/variables).
83
83
84
-

84
+
!!! note
85
+
86
+
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).
85
87
86
88
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`.
87
89
@@ -109,19 +111,30 @@ Function that are conditions or expressions must return a value. The returned va
109
111
110
112
### Use variables from function events
111
113
112
-
Variable can be useful within functions for intermediary results or to keep a state in the extension.
113
-
From function events, expressions must be used to access variable values:
114
+
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**.
114
115
115
-
-`GlobalVariable(MyVariable)` for global variables
116
-
-`Variable(MyVariable)` for scene variables
117
-
-`MyObject.Variable(MyVariable)` for object variables
116
+
!!! tip
117
+
118
+
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.
118
119
119
120
## Use functions in events
120
121
121
122
Extension functions can be found in conditions and actions lists like any other feature of the engine.
122
123
123
124

124
125
126
+
## Write functions dedicated to your project
127
+
128
+
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.
129
+
130
+
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.
131
+
132
+

133
+
134
+
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.
135
+
136
+

137
+
125
138
## Advanced usages
126
139
127
140
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.
0 commit comments