Skip to content

Rules for code that touches Intrigues

These four rules keep your code safe next to the package, in a single-player game and in a multiplayer one. The package’s own code follows them, and the code checks most of them for you. Yours should follow them too.

Every graph runs on the Unity main thread. Call Intrigues from the main thread, too.

The code enforces it. A requirement check from another thread answers “not met” and logs one error. IM.Signal logs an error and delivers nothing. Dice.World() logs one error and gives a roll that changes nothing of the game. (sources: RequirementChecks.cs, SignalHub.cs, Dice.cs)

In a custom node you await real work freely: the continuation is marshalled back to the main thread.

2. Address an actor, never “the player”

Section titled “2. Address an actor, never “the player””

Nodes and code address an actor. To ask whether a human plays one, use the two helpers:

Question Call
Does a human play this actor? IM.IsPlayer(actor)
Does this machine’s player play this actor? IM.IsLocalPlayer(actor)

IsPlayer is true for the local player and, with a multiplayer add-on, for a player on another machine. It is false for null and for every actor the game controls. Do not compare an actor with IM.Player. (source: IM.Players.cs)

The core is host-authoritative. In a single-player game, and on the machine that hosts a multiplayer game, this machine is the host and every change is made here. IM.IsHost tells you.

On any other machine, a call that changes the world is refused. It gives its own “not done” answer (false, null, 0 or nothing) and logs one warning per operation and session. The documentation lists actors’ setters, roles, clans, families, marriages, births, variables, schemes, the clock, the dice and the mind’s settings. Loading, saving and starting a scheme graph are the host’s only. Triggers, signals and the clock’s speed are requests to the host when an add-on can carry them; what the Multiplayer add-on carries is on the Host-aware game code page. (source: Authority.cs) Reads can differ too: Mind.Opinion answers 0 on a client, because opinions are the host’s.

In a single-player game this rule costs you nothing. For multiplayer, read Host-aware code.

Use Dice, not UnityEngine.Random, System.Random or Guid.NewGuid, for anything that matters to the story. A roll is a hash of the world seed, a salt, a stream and a counter, so the same game gives the same rolls and a save keeps where the dice stand. (source: Dice.cs)

Call What it gives
Dice.Value A number from 0 (included) to 1 (excluded).
Dice.Range(int, int), Dice.Range(float, float) A number from min (included) to max (excluded).
Dice.Chance(float percent) True with that chance, 0 to 100.
Dice.World() The next roll of the world, a DiceRoll.
Dice.Stable(a, b, c, d) A roll with no state: the same keys give the same roll for the whole game. Any thread.
flow.Roll() In a node: the visit’s dice. Call it once per visit.

Example. Compiled against the package’s runtime assembly; not run in Unity.

if (Dice.Chance(30f))
{
// True about 30 times in 100. A new game with the same world seed and the same calls rolls the same way.
}

See Chance, dice and seeds.

What you see Why
A warning that an operation “was refused: only the host may change the world”. You changed the world on a client (rule 3). Send a command to the host instead.
The same game gives different outcomes each run. Something may have rolled with UnityEngine.Random (rule 4).