diff --git a/automated_updates_data.json b/automated_updates_data.json index c6d8df7148f..f188c113665 100644 --- a/automated_updates_data.json +++ b/automated_updates_data.json @@ -64,6 +64,10 @@ { "date": "2026-02-24", "summary": "Fixed custom behavior lifecycle method names (onStepPreEvents/onStepPostEvents → doStepPreEvents/doStepPostEvents) and updated collisions doc to reference Physics 2 instead of deprecated Physics behavior" + }, + { + "date": "2026-03-01", + "summary": "Improved network docs with all HTTP methods, async behavior, error variable semantics, CORS note; improved gamepad docs with StickForceX/Y, TriggerPressure, deadzone, controller type detection, and Firefox vibration warning" } ] } diff --git a/docs/gdevelop5/all-features/gamepad/index.md b/docs/gdevelop5/all-features/gamepad/index.md index adb140b4cfe..c5b189fc1db 100644 --- a/docs/gdevelop5/all-features/gamepad/index.md +++ b/docs/gdevelop5/all-features/gamepad/index.md @@ -66,10 +66,21 @@ Detecting pressed buttons can be done with the **Gamepad button pressed** (or ** #### Handle sticks -`Gamepads::StickAngle` and `Gamepads::StickForce` [expressions](/gdevelop5/all-features/expressions) can be used to apply a force on an object. +The following [expressions](/gdevelop5/all-features/expressions) let you read analog stick values: + +- `Gamepads::StickAngle(gamepadNumber, stick)` — angle the stick is pushed toward (in degrees). +- `Gamepads::StickForce(gamepadNumber, stick)` — overall force/magnitude of the stick push (0 to 1). +- `Gamepads::StickForceX(gamepadNumber, stick)` — horizontal axis of the stick (−1 = fully left, 1 = fully right). +- `Gamepads::StickForceY(gamepadNumber, stick)` — vertical axis of the stick (−1 = fully up, 1 = fully down). + +For triggers (LT / RT / L2 / R2), use `Gamepads::TriggerPressure(gamepadNumber, trigger)` which returns a value from 0 (not pressed) to 1 (fully pressed). This allows smooth acceleration or braking in racing games, for example. ![](gamepad-stick-expression.png) +#### Deadzone + +Small stick movements near the center are often caused by imprecision in the hardware. GDevelop applies a **deadzone** (default 0.2) that ignores stick values below that threshold. You can change the deadzone with the action **"Set the deadzone of a gamepad stick"** or read it with the expression `Gamepads::Deadzone(gamepadNumber)`. + ## Handle several players on the same device ### Detect connected gamepads @@ -81,9 +92,17 @@ Each gamepad connected to the computer or phone is numbered from 1 to 4: ![](gamepad-condition-connected.png) +### Detect controller type + +Use the condition **"Type of gamepad"** or the expression `Gamepads::GamepadType(gamepadNumber)` to identify the kind of controller connected (Xbox, PS4, Steam Deck, etc.). This lets you display the correct button icons in your UI — for example, showing a cross button for PlayStation players and an A button for Xbox players. + ## Vibrate a gamepad Use the action **Gamepad vibration** to make a gamepad vibrate. **Advanced Gamepad vibration** allows to setup vibration magnitudes for low and high frequency rumble motors. Each player can have different rumble values. + +!!! warning + + Advanced vibration is not supported on Firefox. diff --git a/docs/gdevelop5/all-features/network/index.md b/docs/gdevelop5/all-features/network/index.md index 1271f4d58fa..a7143097af3 100644 --- a/docs/gdevelop5/all-features/network/index.md +++ b/docs/gdevelop5/all-features/network/index.md @@ -14,25 +14,49 @@ Games and applications work similarly to send or get data to a server: * they send a request to a specific address (also called an endpoint). Optionally, the request can include parameters. * the server sends back a response. The set of all requests that are handled by a server is sometimes called an API. -In addition to the address and the parameters, HTTP requests can have a "verb" associated as well. Requests to get data or fetch a webpage are usually "GET" requests. Requests to post data are usually "POST" requests. +In addition to the address and the parameters, HTTP requests can have a "verb" (called the HTTP **method**) associated as well. GDevelop supports the following methods: **GET**, **POST**, **PUT**, **DELETE**, **PATCH**, **HEAD**, and **OPTIONS**. -GDevelop provides the action called "Send a request to a web page". You can specify the host and the path to the API/web page to be called (for example, if your "endpoint" is `https://mygame.com/api/store-score`, the host is `https://mygame.com` and the path is `/api/store-score` (don't forget the slash /)). You can also specify the content of the request (the parameter that will be received by the server). +- **GET** — fetch data from the server (default). +- **POST** — send new data to the server. +- **PUT** / **PATCH** — update existing data on the server. +- **DELETE** — remove data on the server. -When the server sends the response, it is saved in a variable so that you can read what was sent. +GDevelop provides the action **"Send a request to a web page"**. You enter the full URL of the API endpoint (for example `https://mygame.com/api/store-score`). You can also specify the body content of the request, the HTTP method, and an optional Content-Type header. + +!!! note + + This action is **asynchronous**: the game continues running while the request is sent and the server's response arrives. The response variable and error variable are populated when the server replies — they will **not** have a value immediately on the next line of events. Use a condition that checks the variable (e.g., "Variable text is not empty") in a subsequent event to react to the response. + +## How to handle the response and errors + +When the server replies, the response body is stored as text in the **response variable** you specify. If the server returns JSON, use the action "Convert JSON to a scene variable" afterwards to parse it into a structure variable you can explore with child variables. + +Use the optional **error variable** to detect problems: + +- If the server returns an **HTTP status code ≥ 400** (e.g., 404, 500), the error variable is set to that status code as a string (e.g., `"404"`). +- If the request could not be sent at all (no internet connection, or CORS issue), the error variable is set to `"REQUEST_NOT_SENT"`. + +Check the error variable in a condition to show an error message or retry the request. + +!!! warning + + Web games must comply with **CORS (Cross-Origin Resource Sharing)**. If the server does not send the appropriate `Access-Control-Allow-Origin` header, the request will fail with `"REQUEST_NOT_SENT"`. This restriction does not apply to desktop/mobile builds. ## How to format the content -* For GET requests, parameters have to be sent in the content in the format of a "query string": +* For **GET** requests, parameters are usually appended to the URL as a query string, or placed in the body in the format: `parameter1=value1¶meter2=value2¶meter3=value3`... You can send data from a variable, for example: `"score=" + VariableString(Score) + "&playerName=" + VariableString(Name)` -* For POST requests, it depends on what is expected by the server, but most of the time the server expects JSON formatted text. +* For **POST** and **PUT** requests, it depends on what is expected by the server, but most of the time the server expects JSON formatted text. Set the **Content-Type** to `application/json` in this case. You can either construct it yourself: `"{\"score\": " + VariableString(Score) + " }"` (note the use of backslash before the quote `\"`, to allow the quote to be used inside a text) or use the expression to convert a variable structure to JSON: `ToJSON(VariableWithData)` (see more about this below). +The **Content-Type** defaults to `application/x-www-form-urlencoded` if left empty. + ## Converting variables to JSON and back to variables ### Variable to JSON