Skip to content

Commit c6fccba

Browse files
authored
[Custom extension] Fix no longer relevant explanations (#294)
1 parent 8d37e7e commit c6fccba

File tree

9 files changed

+44
-17
lines changed

9 files changed

+44
-17
lines changed
Loading

docs/gdevelop5/behaviors/events-based-behaviors/index.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Behaviors are grouped into [extensions](/gdevelop5/extensions). They are the sam
3131

3232
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).
3333

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**.
3535

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

3838
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.
3939

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

143143
### Use actions and conditions to manipulate the properties
144144

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`.
147146

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.
151148

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+
![](generate-property-accessors.png)
153150

154151
## Behaviors using other behaviors as properties
155152

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

165162
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.
166163

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+
![](platformer-enemy-extension.png)
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+
167176
## A word about the advantages of behaviors
168177

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

179188
## Examples/ideas for custom behaviors
180189

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/)
193+
- [Flash object](https://wiki.gdevelop.io/gdevelop5/extensions/flash/)
194+
181195
You can imagine tons of different behaviors. Here are a few examples:
182196

183197
* A behavior to **manage the health of an enemy or a boss**.
Loading
Loading

docs/gdevelop5/events/functions/index.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Functions are grouped into [extensions](/gdevelop5/extensions). They are the sam
2525

2626
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).
2727

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**.
2929

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

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

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

8080
#### Use parameter values
8181

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).
8383

84-
![](functionn-parameter-condition.png)
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).
8587

8688
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`.
8789

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

110112
### Use variables from function events
111113

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**.
114115

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.
118119

119120
## Use functions in events
120121

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

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

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+
![](platformer-player-extension.png)
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+
![](platformer-player-extension-usage.png)
137+
125138
## Advanced usages
126139

127140
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.
Loading
Loading

0 commit comments

Comments
 (0)