Skip to Content
defold-typescript libraries
defold (official)

defold/extension-crazygames/crazygames

Functions and constants for interacting with the CrazyGames SDK APIs

  • GitHub: defold/extension-crazygames — pinned to 1.3.0 (released while Defold 1.13.1 was current)
    1. Pick a release from defold/extension-crazygames releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as crazygames from "crazygames"

Functions

crazygames.get_environment(): string

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

Returns

  • environment: string

crazygames.get_game_settings(): table

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

Returns

  • settings: table — The current settings table, or nil if settings are unavailable.

crazygames.add_settings_change_listener(callback: 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.

crazygames.remove_settings_change_listener()

Remove the currently registered game-settings listener.

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

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

crazygames.loading_start()

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

crazygames.loading_stop()

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

crazygames.happytime()

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

crazygames.report_game_completed_percentage(percentage: number)

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(context: table)

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

Clear the game context previously supplied with set_game_context.

crazygames.show_rewarded_ad(callback: function)

Show a rewarded ad.

Parameters

  • callback: function

crazygames.show_midgame_ad(callback: function)

Show a midgame ad.

Parameters

  • callback: function

crazygames.has_ad_block(callback: 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.

crazygames.request_banner(div: string, width: number, height: number)

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

Parameters

  • div: string
  • width: number
  • height: number

crazygames.request_responsive_banner(div: string)

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(div: string)

Clear a banner. Will also hide it.

Parameters

  • div: string

crazygames.clear_all_banners()

Clear all banners.

crazygames.invite_link(params: table): string

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

Parameters

  • params: table

Returns

  • link: string

crazygames.show_invite_button(params: table): string

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

  • link: string

crazygames.hide_invite_button()

Hide the invite button when it is no longer necessary.

crazygames.get_invite_param(key: string): string

Get an invite link parameter.

Parameters

  • key: string

Returns

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

crazygames.get_invite_params(): table

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

Returns

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

crazygames.is_instant_multiplayer(): boolean

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

Returns

  • instant: boolean

crazygames.update_room(room: table)

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

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

crazygames.add_join_room_listener(callback: 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.

crazygames.remove_join_room_listener()

Remove the currently registered join-room listener.

crazygames.clear_data()

Remove all stored game data from the CrazyGames data module.

crazygames.get_item(key: string): string

Get a stored value from the CrazyGames data module.

Parameters

  • key: string

Returns

  • value: string — The stored value, or nil if the key does not exist.

crazygames.remove_item(key: string)

Remove a stored value from the CrazyGames data module.

Parameters

  • key: string

crazygames.set_item(key: string, value: string)

Store a value in the CrazyGames data module.

Parameters

  • key: string
  • value: string

crazygames.get_system_info(): table

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

Returns

  • system_info: table — The current system information, or nil if it is unavailable.

crazygames.list_friends(page: number, size: number, callback: 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. ⚠️ 1-based; passed to crazygames unchanged.
  • 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(encrypted_score: string, score: number)

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(): boolean

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

Returns

  • available: boolean

crazygames.get_user(callback: 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 table

crazygames.get_user_token(callback: 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 token

crazygames.get_xsolla_user_token(callback: 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 token

crazygames.track_order(provider: string, order: table)

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(callback: 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 table

crazygames.set_auth_listener(callback: 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 table

crazygames.remove_auth_listener()

Remove any previously set auth listener.

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

On this page

Functionscrazygames.get_environment(): stringcrazygames.get_game_settings(): tablecrazygames.add_settings_change_listener(callback: function)crazygames.remove_settings_change_listener()crazygames.gameplay_start()crazygames.gameplay_stop()crazygames.loading_start()crazygames.loading_stop()crazygames.happytime()crazygames.report_game_completed_percentage(percentage: number)crazygames.set_game_context(context: table)crazygames.clear_game_context()crazygames.show_rewarded_ad(callback: function)crazygames.show_midgame_ad(callback: function)crazygames.has_ad_block(callback: function)crazygames.request_banner(div: string, width: number, height: number)crazygames.request_responsive_banner(div: string)crazygames.clear_banner(div: string)crazygames.clear_all_banners()crazygames.invite_link(params: table): stringcrazygames.show_invite_button(params: table): stringcrazygames.hide_invite_button()crazygames.get_invite_param(key: string): stringcrazygames.get_invite_params(): tablecrazygames.is_instant_multiplayer(): booleancrazygames.update_room(room: table)crazygames.left_room()crazygames.add_join_room_listener(callback: function)crazygames.remove_join_room_listener()crazygames.clear_data()crazygames.get_item(key: string): stringcrazygames.remove_item(key: string)crazygames.set_item(key: string, value: string)crazygames.get_system_info(): tablecrazygames.list_friends(page: number, size: number, callback: function)crazygames.submit_score(encrypted_score: string, score: number)crazygames.is_user_account_available(): booleancrazygames.get_user(callback: function)crazygames.get_user_token(callback: function)crazygames.get_xsolla_user_token(callback: function)crazygames.track_order(provider: string, order: table)crazygames.show_auth_prompt(callback: function)crazygames.set_auth_listener(callback: function)crazygames.remove_auth_listener()crazygames.show_account_link_prompt(callback: function)