Skip to content

Commit 58c5f2e

Browse files
authored
Add screenshot to import JS files in extensions
1 parent 7d7f68a commit 58c5f2e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
318 KB
Loading

docs/gdevelop5/events/js-code/javascript-in-extensions/index.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ for (const player of players) {
111111

112112
After getting the events function parameter values, you can pass them to a JavaScript function.
113113

114-
#### Call a "static" function of the library
114+
#### Call a "static" function of the library
115115

116116
```javascript
117117
gdjs._myNewExtension.doSomething(myParameter);
@@ -161,7 +161,7 @@ In case you are writing your first custom behavior, please refer to the [custom
161161

162162
### Get an object behavior in Javascript
163163

164-
Behaviors parameter values are actually just a string of the behavior name. Each object instance has their own behavior instance so it avoids to pass an array for behaviors when they can be mapped from objects with `object.getBehavior(behaviorName)`.
164+
Behaviors parameter values are actually just a string of the behavior name. Each object instance has their own behavior instance so it avoids to pass an array for behaviors when they can be mapped from objects with `object.getBehavior(behaviorName)`.
165165

166166
For actions and conditions of behaviors, the object parameter **Object** only contains one instance because GDevelop does the iteration on object instances. For other object parameters you still need to iterate on all instances.
167167

@@ -214,14 +214,19 @@ This is a few instances of extensions that use JavaScript:
214214

215215
## Experimental new option: JavaScript files in your project
216216

217-
Starting with GDevelop 5.5.222, you can also open the extension properties, and then add a JavaScript source file.
217+
Starting with GDevelop 5.5.222, you can also open the extension properties, and then add a JavaScript source file:
218+
219+
![Add a JavaScript file to an extension](./extra-source-files.png)
220+
218221
This source file will be:
219222

220-
- imported as the same time as the files of the game engine or other extensions. It can either be set to be imported before the game engine files or after (but the order between files is not guaranteed).
223+
- **only imported if the extension is used** in your game (for example, a scene uses an action or condition from the extension).
224+
- imported as the same time as the files of the game engine or other extensions. It can either be set to be imported before the game engine files or after (but the order between files is not guaranteed). It works both for the preview and when the game is exported.
221225
- no transpilation or changes are done on the file.
222226
- the file will be added as a "JavaScript" resource in the resources editor.
223227

224228
!!! warning
225229

230+
Remember to make sure your extension is used by the game so that the file is included.
226231
If you export your extension, this file *won't* be included. Consider this option as an experimental option to add custom JavaScript code to a project.
227232

0 commit comments

Comments
 (0)