Skip to content
Open
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
4 changes: 4 additions & 0 deletions automated_updates_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
{
"date": "2026-04-02",
"summary": "Improved multiplayer docs: added Quick Join section, documented player username/ping/last-joined/last-left expressions, lobby ID expression, custom message variable variant, and synchronization rate action"
},
{
"date": "2026-04-15",
"summary": "Fixed js-code/index.md: corrected deleteFromScene() and getElapsedTime() signatures (no longer take runtimeScene param), added examples for global variables access and object creation from JavaScript"
}
]
}
29 changes: 27 additions & 2 deletions docs/gdevelop5/events/js-code/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ objects.forEach(object => {

if (enemy.getAnimation() === 1 && platformerBehavior.isOnFloor() && !platformerBehavior.isMoving()) {
object.activateBehavior("PlatformerObject", false);
enemy.setOpacity(enemy.getOpacity() - 50 * object.getElapsedTime(runtimeScene) / 1000);
enemy.setOpacity(enemy.getOpacity() - 50 * object.getElapsedTime() / 1000);

if (enemy.getOpacity() === 0) {
object.deleteFromScene(runtimeScene);
object.deleteFromScene();
}
}
});
Expand All @@ -185,6 +185,31 @@ objects.forEach(object => {
The equivalent events would be:
![](fade-out-and-behavior.png)

### Read and change global variables

Global variables are stored on the game object, not the scene. Use `runtimeScene.getGame().getVariables()` to access them:

```javascript
const globalVar = runtimeScene.getGame().getVariables().get("HighScore");
const currentScore = globalVar.getAsNumber();
if (currentScore > 1000) {
globalVar.setNumber(currentScore + 100);
}
```

For a string global variable, use `getAsString()` and `setString()`.

### Create a new instance of an object

Call `runtimeScene.createObject("ObjectName")` to spawn a new instance. The method returns the new object (or `null` if the object name is not found):

```javascript
const newEnemy = runtimeScene.createObject("Enemy");
if (newEnemy !== null) {
newEnemy.setPosition(100, 200);
}
```

### Use JavaScript to get the value of a parameter of a function

When use a JavaScript code block inside a function of an extension, a custom behavior or a custom object, you can access to the **parameters** of this function. The way you access to the parameter depends on the **type** of this parameter.
Expand Down