Skip to content

Game

Settings

The game module contains a settings object, that can be accessed like this:

window.ConstructCrazySDK.game.settings;

The settings object contains:

Happy time

The happytime() method can be called on various player achievements (beating a boss, reaching a highscore, etc.). It makes the website celebrate (for example by launching some confetti). There is no need to call this when a level is completed, or an item is obtained.

window.ConstructCrazySDK.game.happytime();

Gameplay start/stop

We provide functions that enable us to track when and how users are playing your games. These can be used to ensure our site does not perform resource-intensive actions while a user is playing.

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

The gameplayStop() function has to be called on every game break (entering a menu, switching levels, pausing the game, ...) don't forget to call gameplayStart() when the gameplay resumes.

window.ConstructCrazySDK.game.gameplayStart();
window.ConstructCrazySDK.game.gameplayStop();

This feature lets you share the Crazygames version of your game with the players and invite them to join a multiplayer game. You can call inviteLink with a map of parameters that correspond to your game or game room.

localVars.inviteLink = await window.ConstructCrazySDK.game.inviteLink({
    roomId: 12345,
    param2: "value",
    param3: "value",
});

When a player joins through an invite link, you can get the room ID like this:

const roomId = window.ConstructCrazySDK.game.getInviteParam("roomId"); // it returns either a string or null if the parameter is missing

The easiest way is to insert the invite link room code detection is when the SDK initializes:

const sdkElem = document.createElement("script");
sdkElem.type = "text/javascript";
sdkElem.src = "https://sdk.crazygames.com/Construct3CrazySDK-v3.js";
document.body.appendChild(sdkElem);
sdkElem.onload = function () {
    window.ConstructCrazySDK.init().then(() => {
        const roomId = window.ConstructCrazySDK.game.getInviteParam("roomId");
        console.log("Room id:", roomId);

        if (roomId) {
            runtime.globalVars.roomId = roomId;
            runtime.goToLayout("RoomLayout");
        } else {
            runtime.goToLayout("NextLayout");
        }
    });
};

Instant multiplayer

The game module contains the isInstantMultiplayer flag, that can be accessed like this:

const instantMultiplayer = window.CrazyGames.SDK.game.isInstantMultiplayer; // it returns a boolean

The easiest way is to use it is when the SDK initializes:

const sdkElem = document.createElement("script");
sdkElem.type = "text/javascript";
sdkElem.src = "https://sdk.crazygames.com/Construct3CrazySDK-v3.js";
document.body.appendChild(sdkElem);
sdkElem.onload = function () {
    window.ConstructCrazySDK.init().then(() => {
        const instantMultiplayer =
            window.CrazyGames.SDK.game.isInstantMultiplayer;
        console.log("Instant multiplayer:", instantMultiplayer);

        if (instantMultiplayer) {
            // should instantly create a new room/lobby
        } else {
            runtime.goToLayout("NextLayout");
        }
    });
};

For multiplayer games, if isInstantMultiplayer is true, you should instantly create a new room/lobby for the user. Read more about this on multiplayer requirements page.