diff --git a/docs/gdevelop5/events/js-code/javascript-in-extensions/index.md b/docs/gdevelop5/events/js-code/javascript-in-extensions/index.md index a6d629f139..1f70ccf2e1 100644 --- a/docs/gdevelop5/events/js-code/javascript-in-extensions/index.md +++ b/docs/gdevelop5/events/js-code/javascript-in-extensions/index.md @@ -97,7 +97,9 @@ const angle = eventsFunctionContext.getArgument("Angle"); ![](wrap-function.png) -For object parameters, `getObjects` must be used. It gives an `Array` of `RuntimeObject`. +### Get object parameters in JavaScript + +For object parameters, `getObjects` must be used. It gives an `Array` of `gdjs.RuntimeObject`. ```javascript const players = eventsFunctionContext.getObjects("Player"); @@ -107,6 +109,35 @@ for (const player of players) { } ``` +When you chose a specific type for the object in the parameter list, you need to declare the type in the code to get all the autocompletions. For instance, for sprite objects, you will add the following: + +```javascript +/** @type {Array} */ +const players = eventsFunctionContext.getObjects("Player"); +``` +You can find the list of all object types in the [GDJS documentation page for RuntimeObject](https://docs.gdevelop.io/GDJS%20Runtime%20Documentation/classes/gdjs.RuntimeObject.html). + + +### Get resources in JavaScript + +Resource parameters are strings containing the name of the resource. You can get the resource content from some [ResourceManager](https://docs.gdevelop.io/GDJS%20Runtime%20Documentation/interfaces/gdjs.ResourceManager.html). + +For instance, to get an image for a 2D game you can do as follows: + +```javascript +const resourceName = eventsFunctionContext.getArgument("MyImage"); +runtimeScene.getGame().getImageManager().getPIXITexture(resourceName); +``` + +For 3D games, you can get a texture with this other method: +```javascript +runtimeScene.getGame().getImageManager().getThreeTexture(resourceName); +``` + +!!! warning + + By default, resource names look like a relative path, but it should not be used as a path because it won't necessarily be a valid path (and it can be changed by users to anything). + ### Call a library from an event-function After getting the events function parameter values, you can pass them to a JavaScript function. diff --git a/docs/gdevelop5/events/js-code/javascript-in-extensions/library-declaration-events.png b/docs/gdevelop5/events/js-code/javascript-in-extensions/library-declaration-events.png index 218822cb51..54fafb247e 100644 Binary files a/docs/gdevelop5/events/js-code/javascript-in-extensions/library-declaration-events.png and b/docs/gdevelop5/events/js-code/javascript-in-extensions/library-declaration-events.png differ