Skip to main content
Version: 0.4.1

Guestbook

A book everyone can sign. Clicking it adds a line with the player's name to a synced list of up to six strings of 40 bytes each; when the page is full the oldest line drops off. The title is a synced string longer than the default 60 bytes. Other players redraw the page in OnSyncedChanged, which tells them which field changed.

The three synced fields use 94 of the script's 96 words: the list 1 + 6 × (1 + 40 / 4) = 67, the title 1 + 100 / 4 = 26 and the count 1.

Put it on an interactable object, set Page and Status to two TextMeshPro labels, and optionally call ClearPage from a UI button.

Guestbook.cs
using System.Collections.Generic;
using StageTime.SDK;
using TMPro;

/// <summary>
/// A shared guestbook. Clicking the book signs it: the player takes ownership and adds a line to a synced list of up to
/// six strings (the oldest line drops off when it is full). Everyone else redraws the page in OnSyncedChanged, which
/// names the field that changed. The title is a synced string longer than the default 60 bytes.
/// Synced words: entries 1 + 6 × (1 + 40 / 4) = 67, title 1 + 100 / 4 = 26, signatures 1: 94 of 96.
/// </summary>
public class Guestbook : StageTimeBehaviour
{
public TMP_Text page;
public TMP_Text status;

[Synced, MaxLength(6, 40)] private List<string> entries = new List<string>();
[Synced, MaxLength(100)] private string title = "Welcome to the StageTime guestbook! Click the book to sign it.";
[Synced] private int signatures;

private int remoteChanges;
private string lastChange = "none";

private void Start() => Redraw();

public override void Interact()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
if (entries.Count == 6) entries.RemoveAt(0);
signatures++;
string name = Networking.LocalPlayer != null ? Networking.LocalPlayer.displayName : "Guest";
entries.Add("#" + signatures + " " + name); // longer names are cut to 40 bytes
Redraw();
}

/// <summary>Wipes the page (a UI button: On Click → SendCustomEvent "ClearPage").</summary>
public void ClearPage()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
entries.Clear();
Redraw();
}

public override void OnSyncedChanged(string field)
{
remoteChanges++;
lastChange = field;
if (field == nameof(entries) || field == nameof(title)) Redraw();
else UpdateStatus();
}

private void Redraw()
{
if (page != null)
{
string text = title;
foreach (string line in entries) text += "\n" + line;
if (entries.Count == 0) text += "\n(no signatures yet)";
page.text = text;
}
UpdateStatus();
}

private void UpdateStatus()
{
if (status != null) status.text = $"{signatures} signatures, {entries.Count} shown | updates from others: {remoteChanges} (last: {lastChange})";
}
}