Big Puzzle SDK GitHub

Scripting

You can create pretty complex puzzles with the built in SDK functions, but if you need more complex logic you can write your own C# scripts.

Where your scripts go

Your scripts must be in the Assets/PuzzleScripts folder. The SDK creates it for you when you import it (or click Tools > Big Puzzle SDK > Setup > Set up scripts folder).

A first script

using System.Collections.Generic;
using BigPuzzleSDK;
using UnityEngine;

public class AllBoardsCorrect : MonoBehaviour {
    [SerializeField] private List<PuzzlePegBoard> boards;

    // Wire each Peg Board's On Correct to this.
    public void BoardCorrect() {

        // Only run this logic if you are host.
        if (!PuzzleSDK.IsHost) return;

        foreach (PuzzlePegBoard board in boards) {
            if (!board.IsCorrect) return;
        }
        OnSuccess();
    }

    private void OnSuccess() {
        // Do something here, like opening a door or calling PuzzleSDK.Win().
    }
}

The PuzzleSDK class

Member What it does
PuzzleSDK.IsHost Static. True on the host, and in single player.
Win() Host only. Fires every Confetti and releases every Gourd Vice, then On Win.
IsWon Read-only. The puzzle has been won.
IsRunning Read-only. A Start Switch is on.

Synced variables

Type Holds Range
SyncedInt A whole number -8,388,608 to 8,388,607
SyncedBool True or false
SyncedEvent Nothing: a call that every player runs argument -128 to 127

How they work, in the same four rules as everything else:

SyncedInt

using BigPuzzleSDK;
using UnityEngine;

public class Score : MonoBehaviour {
    // Make synced variables as fields, like this
    private readonly SyncedInt score = new SyncedInt("score");

    void Awake() {
        score.Changed += value => Debug.Log("score is now " + value);
    }

    void Update() {
        // Calls on other PCs are ignored, so this is safe to run everywhere
        if (Input.GetKeyDown(KeyCode.Alpha1)) score.Add(1);
        if (Input.GetKeyDown(KeyCode.Alpha2)) score.Add(-1);
    }
}

new SyncedInt(name, initialValue = 0)

Member What it does
Value The current value. Read-only.
Changed event Action<int>: runs on every PC with the new value.
Set(int) Host only. Kept between -8,388,608 and 8,388,607.
Add(int) Host only. A negative number takes away.

SyncedBool

private readonly SyncedBool open = new SyncedBool("open");

void Awake() {
    open.Changed += isOpen => door.SetActive(!isOpen);
}

new SyncedBool(name, initialValue = false)

Member What it does
Value The current value. Read-only.
Changed event Action<bool>: runs on every PC with the new value.
Set(bool) Host only.

SyncedEvent

A synced event is a function call that every player runs. It doesn't hold a value.

private readonly SyncedEvent flash = new SyncedEvent("flash");

void Awake() {
    // Runs on every PC, the host's too
    flash.Fired += colorNumber => PlayFlash(colorNumber);
}

public void OnWrongAnswer() {
    flash.Fire(2);   // host only; ignored elsewhere
}

new SyncedEvent(name)

Member What it does
Fire(int argument = 0) Host only. Runs Fired on every PC. The argument is kept between -128 and 127.
Fired event Action<int>: runs on every PC with the argument.

Nothing is saved. A player who joins later does not run events from before they arrived. If players should find something true when they arrive, use a SyncedInt or SyncedBool.