-
Notifications
You must be signed in to change notification settings - Fork 0
General
This module contains general GX.games functionality. These include general purpose functions and also structs that are reused across multiple modules.
This asset contains the following general functions:
This asset contains the following general structs:
When your game is played on GX.games, some extra parameters are passed into the URL of the game so they can be retrieved in-game. This function will return the value of the parameter specified in the first argument as a string.
The following parameter keys can be specified in the key argument:
| Key | Value |
|---|---|
| game | The ID of the game |
| track | The ID of the track that is being played |
| challenge | The ID of the currently active challenge, or undefined if no challenge is active |
| username | The username of the current user |
| userId | The ID of the current user |
| avatarUrl | A URL to the current user's avatar image (can be used with sprite_add() to be displayed in-game) |
Note that if the specified parameter is not present in the URL, this function will return undefined.
Syntax:
gxc_get_query_param(key);| Argument | Type | Description |
|---|---|---|
| key | String | The parameter key to get the value of |
Returns:
String (or undefined)Example:
var _current_challenge = gxc_get_query_param("challenge");
var _highscore_challenge = "34esa3a1-e41e-4a9f-aaaa-4da7bd24ada2";
if (_current_challenge == _highscore_challenge)
{
gxc_challenge_submit_score(global.highscore);
}
The above code retrieves the ID of the currently active challenge and checks whether it's equal to a specific challenge ID (meaning that challenge is active). In that case, it submits the current highscore as a new score to the challenge. Here is an example where the profile data is retrieved and drawn in-game:
// Create event
username = gxc_get_query_param("username");
var _avatar_url = gxc_get_query_param("avatarUrl");
user_sprite = sprite_add(_avatar_url, 0, 0, 0, 0, 0);
// Draw event
if (sprite_exists(user_sprite))
{
draw_sprite(user_sprite, 0, x, y);
draw_text(x + 100, y, username);
}
The "Create event" code above retrieves the username and avatar URL for the current user, then uses sprite_add() to download the avatar image through the given URL and stores its new ID in a variable. In the Draw event, it checks whether the user sprite exists (which will be true after it has been downloaded) and if it does, draws the sprite along with the username.
NOTE : Due to CORS, you will not be able to load the avatar image when the game is running locally. For it to work you are required to have uploaded your game to GXC and run it from there.
The Pagination struct is returned by all the functions that query data from the server as shown in the list below:
-
This struct will contain the following variables:
| Variable | Type | Value |
|---|---|---|
| currPage | Real | The page number that was loaded |
| numPerPage | Real | The number of items on each page |
| totalItems | Real | The total number of items |
| totalPages | Real | The total number of pages that are available for the given page size |
YoYoGames 2023