API
API
Lua

Defold Learn logo


crazygames

Version: stable

FUNCTIONS
crazygames.get_environment()
crazygames.get_game_settings()
crazygames.add_settings_change_listener()
crazygames.remove_settings_change_listener()
crazygames.gameplay_start()
crazygames.gameplay_stop()
crazygames.loading_start()
crazygames.loading_stop()
crazygames.happytime()
crazygames.report_game_completed_percentage()
crazygames.set_game_context()
crazygames.clear_game_context()
crazygames.show_rewarded_ad()
crazygames.show_midgame_ad()
crazygames.has_ad_block()
crazygames.request_banner()
crazygames.request_responsive_banner()
crazygames.clear_banner()
crazygames.clear_all_banners()
crazygames.invite_link()
crazygames.show_invite_button()
crazygames.hide_invite_button()
crazygames.get_invite_param()
crazygames.get_invite_params()
crazygames.is_instant_multiplayer()
crazygames.update_room()
crazygames.left_room()
crazygames.add_join_room_listener()
crazygames.remove_join_room_listener()
crazygames.clear_data()
crazygames.get_item()
crazygames.remove_item()
crazygames.set_item()
crazygames.get_system_info()
crazygames.list_friends()
crazygames.submit_score()
crazygames.is_user_account_available()
crazygames.get_user()
crazygames.get_user_token()
crazygames.get_xsolla_user_token()
crazygames.track_order()
crazygames.show_auth_prompt()
crazygames.set_auth_listener()
crazygames.remove_auth_listener()
crazygames.show_account_link_prompt()

Functions

crazygames.get_environment()

crazygames.get_environment()

Get the CrazyGames SDK environment. SDK functionality should only be used when the result is "local" or "crazygames".

PARAMETERS

None

RETURNS

string

crazygames.get_game_settings()

crazygames.get_game_settings()

Get the current CrazyGames game settings, including muteAudio and disableChat.

PARAMETERS

None

RETURNS

table The current settings table, or nil if settings are unavailable.

crazygames.add_settings_change_listener()

crazygames.add_settings_change_listener(callback)

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.

crazygames.remove_settings_change_listener()

crazygames.remove_settings_change_listener()

Remove the currently registered game-settings listener.

PARAMETERS

None


crazygames.gameplay_start()

crazygames.gameplay_start()

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.)

PARAMETERS

None


crazygames.gameplay_stop()

crazygames.gameplay_stop()

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

PARAMETERS

None


crazygames.loading_start()

crazygames.loading_start()

The loadingStart() function has to be called whenever you start loading your game.

PARAMETERS

None


crazygames.loading_stop()

crazygames.loading_stop()

The loadingStop() function has to be called when the loading is complete and eventually the gameplay starts.

PARAMETERS

None


crazygames.happytime()

crazygames.happytime()

Celebrate a major player achievement, such as beating a boss or reaching a high score.

PARAMETERS

None


crazygames.report_game_completed_percentage()

crazygames.report_game_completed_percentage(percentage)

Report the player's current game-completion percentage to CrazyGames. The value must be between 0 and 100.

PARAMETERS

percentage number

crazygames.set_game_context()

crazygames.set_game_context(context)

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

crazygames.clear_game_context()

crazygames.clear_game_context()

Clear the game context previously supplied with set_game_context.

PARAMETERS

None


crazygames.show_rewarded_ad()

crazygames.show_rewarded_ad(callback)

Show a rewarded ad.

PARAMETERS

callback function

crazygames.show_midgame_ad()

crazygames.show_midgame_ad(callback)

Show a midgame ad.

PARAMETERS

callback function

crazygames.has_ad_block()

crazygames.has_ad_block(callback)

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.

crazygames.request_banner()

crazygames.request_banner(div,width,height)

Request a banner. The container will be resized to the specified width.

PARAMETERS

div string
width number
height number

crazygames.request_responsive_banner()

crazygames.request_responsive_banner(div)

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

crazygames.clear_banner()

crazygames.clear_banner(div)

Clear a banner. Will also hide it.

PARAMETERS

div string

crazygames.clear_all_banners()

crazygames.clear_all_banners()

Clear all banners.

PARAMETERS

None


crazygames.invite_link()

crazygames.invite_link(params)

Create a link to your game to invite others to join a multiplayer game.

PARAMETERS

params table

RETURNS

string

crazygames.show_invite_button()

crazygames.show_invite_button(params)

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

string

crazygames.hide_invite_button()

crazygames.hide_invite_button()

Hide the invite button when it is no longer necessary.

PARAMETERS

None


crazygames.get_invite_param()

crazygames.get_invite_param(key)

Get an invite link parameter.

PARAMETERS

key string

RETURNS

string The parameter value, or nil if the parameter is missing.

crazygames.get_invite_params()

crazygames.get_invite_params()

Get all invite parameters supplied when the game was opened from an invite link.

PARAMETERS

None

RETURNS

table The invite parameters, or nil if the game was not opened from an invite link.

crazygames.is_instant_multiplayer()

crazygames.is_instant_multiplayer()

For multiplayer games, if is_instant_multiplayer() returns true, you should instantly create a new room/lobby for the user.

PARAMETERS

None

RETURNS

boolean

crazygames.update_room()

crazygames.update_room(room)

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

crazygames.left_room()

crazygames.left_room()

Notify CrazyGames that the player has left the current multiplayer room.

PARAMETERS

None


crazygames.add_join_room_listener()

crazygames.add_join_room_listener(callback)

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.

crazygames.remove_join_room_listener()

crazygames.remove_join_room_listener()

Remove the currently registered join-room listener.

PARAMETERS

None


crazygames.clear_data()

crazygames.clear_data()

Remove all stored game data from the CrazyGames data module.

PARAMETERS

None


crazygames.get_item()

crazygames.get_item(key)

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.

crazygames.remove_item()

crazygames.remove_item(key)

Remove a stored value from the CrazyGames data module.

PARAMETERS

key string

crazygames.set_item()

crazygames.set_item(key,value)

Store a value in the CrazyGames data module.

PARAMETERS

key string
value string

crazygames.get_system_info()

crazygames.get_system_info()

Get information about the user's locale, country, device, operating system, browser, and CrazyGames application type.

PARAMETERS

None

RETURNS

table The current system information, or nil if it is unavailable.

crazygames.list_friends()

crazygames.list_friends(page,size,callback)

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.

crazygames.submit_score()

crazygames.submit_score(encrypted_score,score)

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.

crazygames.is_user_account_available()

crazygames.is_user_account_available()

Before using any user account features, you should always ensure that the user account system is available.

PARAMETERS

None

RETURNS

boolean

crazygames.get_user()

crazygames.get_user(callback)

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 table

crazygames.get_user_token()

crazygames.get_user_token(callback)

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 token

crazygames.get_xsolla_user_token()

crazygames.get_xsolla_user_token(callback)

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 token

crazygames.track_order()

crazygames.track_order(provider,order)

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.

crazygames.show_auth_prompt()

crazygames.show_auth_prompt(callback)

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 table

crazygames.set_auth_listener()

crazygames.set_auth_listener(callback)

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 table

crazygames.remove_auth_listener()

crazygames.remove_auth_listener()

Remove any previously set auth listener.

PARAMETERS

None


crazygames.show_account_link_prompt(callback)

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