Namespace: crazygames
Language: Lua
Type: Extension
Functions and constants for interacting with the CrazyGames SDK APIs
Type: FUNCTION Get the CrazyGames SDK environment. SDK functionality should only be used when the result is “local” or “crazygames”.
Returns
stringType: FUNCTION Get the current CrazyGames game settings, including muteAudio and disableChat.
Returns
table - The current settings table, or nil if settings are unavailable.Type: FUNCTION Register a listener that is called whenever the CrazyGames game settings change. Registering again replaces the previous listener.
Parameters
callback (function) - The function takes two arguments, self and the updated settings table.Type: FUNCTION Remove the currently registered game-settings listener.
Type: FUNCTION The gameplayStart() function has to be called whenever the player starts playing or resumes playing after a break (menu/loading/achievement screen, game paused, etc.)
Type: FUNCTION The gameplayStop() function has to be called on every game break (entering a menu, switching level, pausing the game, …) don’t forget to call gameplayStart() when the gameplay resumes
Type: FUNCTION The loadingStart() function has to be called whenever you start loading your game.
Type: FUNCTION The loadingStop() function has to be called when the loading is complete and eventually the gameplay starts.
Type: FUNCTION Celebrate a major player achievement, such as beating a boss or reaching a high score.
Type: FUNCTION Report the player’s current game-completion percentage to CrazyGames. The value must be between 0 and 100.
Parameters
percentage (number)Type: FUNCTION Attach JSON-serializable game state to feedback submitted by the player. Call clear_game_context when the state is no longer relevant.
Parameters
context (table)Type: FUNCTION Clear the game context previously supplied with set_game_context.
Type: FUNCTION Show a rewarded ad.
Parameters
callback (function)Type: FUNCTION Show a midgame ad.
Parameters
callback (function)Type: FUNCTION Detect if the user has an adblocker.
Parameters
callback (function) - The function takes two arguments, self and a boolean indicating whether an adblocker was detected.Type: FUNCTION Request a banner. The container will be resized to the specified width.
Parameters
div (string)width (number)height (number)Type: FUNCTION The responsive banners feature will request ads that fit into your container, without the need to specify or select a size beforehand.
Parameters
div (string)Type: FUNCTION Clear a banner. Will also hide it.
Parameters
div (string)Type: FUNCTION Clear all banners.
Type: FUNCTION Create a link to your game to invite others to join a multiplayer game.
Parameters
params (table)Returns
stringType: FUNCTION Display a button in the game footer that opens a popup containing an invite link. This CrazyGames feature is deprecated in favor of Room Data, but remains available for existing integrations.
Parameters
params (table)Returns
stringType: FUNCTION Hide the invite button when it is no longer necessary.
Type: FUNCTION Get an invite link parameter.
Parameters
key (string)Returns
string - The parameter value, or nil if the parameter is missing.Type: FUNCTION Get all invite parameters supplied when the game was opened from an invite link.
Returns
table - The invite parameters, or nil if the game was not opened from an invite link.Type: FUNCTION For multiplayer games, if is_instant_multiplayer() returns true, you should instantly create a new room/lobby for the user.
Returns
booleanType: FUNCTION Update the current multiplayer room. The table can contain roomId (string), isJoinable (boolean), and inviteParams (a table of string, number, or boolean values). Only supplied fields are updated.
Parameters
room (table)Type: FUNCTION Notify CrazyGames that the player has left the current multiplayer room.
Type: FUNCTION Register a listener for requests to join a multiplayer room. Registering again replaces the previous listener.
Parameters
callback (function) - The function takes two arguments, self and the invite parameters table.Type: FUNCTION Remove the currently registered join-room listener.
Type: FUNCTION Remove all stored game data from the CrazyGames data module.
Type: FUNCTION Get a stored value from the CrazyGames data module.
Parameters
key (string)Returns
string - The stored value, or nil if the key does not exist.Type: FUNCTION Remove a stored value from the CrazyGames data module.
Parameters
key (string)Type: FUNCTION Store a value in the CrazyGames data module.
Parameters
key (string)value (string)Type: FUNCTION Get information about the user’s locale, country, device, operating system, browser, and CrazyGames application type.
Returns
table - The current system information, or nil if it is unavailable.Type: FUNCTION Retrieve one page of the current user’s CrazyGames friends. Only one list_friends request may be active at a time. The callback receives nil if the request fails.
Parameters
page (number) - Page number, starting at 1.size (number) - Number of friends to retrieve, between 1 and 50.callback (function) - The function takes two arguments, self and the friends-page table.Type: FUNCTION Submit an encrypted score and its plain numeric value to a CrazyGames leaderboard. Leaderboards must be enabled and configured for the game.
Parameters
encrypted_score (string) - The score encrypted with the game’s CrazyGames leaderboard encryption key and encoded as Base64.score (number) - The unencrypted numeric score.Type: FUNCTION Before using any user account features, you should always ensure that the user account system is available.
Returns
booleanType: FUNCTION Retrieve the user currently logged in CrazyGames. If the user is not logged in CrazyGames, the callback receives nil. Will call the provided callback with the logged in user account.
Parameters
callback (function) - The function takes two arguments, self and the user tableType: FUNCTION The user token is in JWT format and contains the userId of the player that is currently logged in to CrazyGames, as well as other useful information. You should send it to your server when required, and verify/decode it there to extract the userId. Will call the provided callback with the token.
Parameters
callback (function) - The function takes two arguments, self and the tokenType: FUNCTION Generates a custom Xsolla token that you use with the Xsolla SDK. Will call the provided callback with the token.
Parameters
callback (function) - The function takes two arguments, self and the xsolla tokenType: FUNCTION Report an in-game purchase order to CrazyGames analytics. Order tracking is optional; use provider “xsolla” for Xsolla orders.
Parameters
provider (string)order (table) - The JSON-serializable order returned by the payment provider.Type: FUNCTION By calling this method, the log in or register popup will be displayed on CrazyGames. The user can log in their existing account, or create a new account. Will call the provided callback on log in.
Parameters
callback (function) - The function takes two arguments, self and the user tableType: FUNCTION You can register a user auth listener that is triggered when the player logs in to CrazyGames. A log out doesn’t trigger the auth listener, since the entire page is refreshed when the player logs out.
Parameters
callback (function) - The function takes two arguments, self and the user tableType: FUNCTION Remove any previously set auth listener.
Type: FUNCTION Show an account linking prompt to link a CrazyGames account to the in-game account. Will call the provided callback with a response table containing either response = “yes” or response = “no”. The response is nil if the prompt fails.
Parameters
callback (function) - The function takes two arguments, self and the response table