Skip to content

Schemes from code

A scheme is drawn in the Studio and started from code. This page lists the calls that start one, ask whether it may start, change who takes part, and hear what happens to it. The concept is on Schemes, and the questions a start asks are on Requirements.

Your game decides that a character plots, or a button starts a plot, or a system must know which plots are open to an actor. Start with StartScheme. Use RequestScheme when the call may come from a client. All of it is main thread. The writers run on the host, as the Scripting overview explains.

All on Actor (Runtime/Actors/Actor.Schemes.cs). The actor you call it on is the Conspirator.

Signature What it does
Scheme StartScheme(string schemeNameOrId, Actor target = null) Starts the scheme against target. Returns the running scheme, or null when it is refused.
Scheme StartScheme(string schemeNameOrId, Actor target, IEnumerable<Actor> accomplices) The same, with accomplices. They are in the scheme’s Accomplices list before its Start node runs.
Scheme StartScheme(string schemeNameOrId, Actor target, StartOptions options) The same with options. StartOptions.IgnoreRequirements skips the requirements that count to start.
Scheme StartScheme(string, Actor, IEnumerable<Actor>, StartOptions) Both.
Scheme StartScheme(Scheme scheme, Actor target = null) and the matching overloads The same, with a scheme object instead of a name.

It returns null when the actor is its own target, when the scheme already runs against that target, when the scheme is unknown or has no graph, or when a requirement to start is not met. The requirements that count while the scheme runs are watched as always, whatever the options say. The returned scheme can already have ended during its own start. Then scheme.SchemeRunner.IsEnded is true, or the runner is gone.

Example, copied from the demo project (Game/Rules/DemoRules.cs, lines 350 and 351). The game starts a scheme and ignores its start requirements.

// The game decides when these start: their requirements, if any, do not count.
scheduled = conspirator.StartScheme(scheme, target, StartOptions.IgnoreRequirements) != null;
Signature What it does
void RequestScheme(Scheme scheme, Actor target, Action<SchemeStartResult> callback, IEnumerable<Actor> accomplices = null) Asks to start the scheme and tells callback how it went.
void RequestScheme(string schemeNameOrId, Actor target, Action<SchemeStartResult> callback, IEnumerable<Actor> accomplices = null) By name or ID. An unknown one is answered Unknown.

In a single-player game and on the host, the callback runs before the call returns. On a client the request goes to the host, which asks the requirements again, and the callback runs on a later frame. It says “not sent” when no session can carry it.

SchemeStartResult has Outcome, Started, SchemeId, Scheme, Conspirator, Target, Check and GetReasons(List<string> into, bool links = false). The outcome is a SchemeStartOutcome: Started, RequirementsNotMet, AlreadyRunning, Unknown, NotAllowed, NotStarted or NotSent.

Example, not compiled. The scheme name is made up.

actor.RequestScheme("Poison the cup", target, result =>
{
if (result.Started) return;
var reasons = new List<string>();
result.GetReasons(reasons); // the unmet requirements, in this machine's language
});
Signature What it does File
RequirementCheck Scheme.CanStart(Actor conspirator, Actor target) The scheme’s requirements that count to start. Another overload takes accomplices. Pass null as the target for a scheme that needs none. Scheme.cs
bool Scheme.CanEverStart(Actor conspirator) False when the scheme can start against nobody for this actor. True does not mean it can start against a given target. Scheme.cs
bool IM.Meets(string setNameOrId, Actor actor, Actor other = null) True when every requirement of a requirement set is met. An unknown set is not met. IM.Schemes.cs
RequirementCheck IM.Check(string setNameOrId, Actor actor, Actor other = null) The same, with the reasons. IM.Schemes.cs
int Actor.GetSchemesFor(Actor target, List<Scheme> into) Fills into (cleared first) with the schemes this actor can start against target. Pass null for schemes that need none. Actor.Schemes.cs

Meets and Check also have a form that takes IReadOnlyList<Actor> accomplices, and so does GetSchemesFor. All of these allocate nothing and run on the main thread. From another thread they answer “not met” and log one error. A requirement that cannot be answered, such as one that reads a target when there is none, is not met.

GetSchemesFor lists a scheme only when it is not already running against the target and no blocking requirement is unmet. A scheme whose requirement says “hide” is left out. Scheme templates are IM.Schemes.

A RequirementCheck has Allowed, Hidden, UnmetCount, WarningCount, Unmet(int index), Reason(int index, Actor conspirator, Actor target, bool links = false), GetReasons(List<string> into, Actor conspirator, Actor target, bool links = false) and the matching warning calls. default is an allowed answer with nothing unmet.

Signature What it does
IEnumerable<Scheme> Schemes The schemes the actor runs.
IEnumerable<Scheme> SchemesAgainstToActor The schemes run against this actor.
IReadOnlyList<Scheme> SchemesAsAccomplice The schemes this actor helps in.
bool SchemeIsActive(string schemeNameOrId) True when the actor runs that scheme. Overloads take a target, or a VerifyType.
Scheme GetScheme(string schemeNameOrId, Actor target = null) The active scheme against that target, or null.
bool TakesPartIn(Scheme scheme) True as conspirator, target or accomplice.

VerifyType is a set of flags: ToTarget, ToAnyone, FromAnyone, FromTarget and AsAccomplice. With several flags, one match is enough.

A scheme object that runs has Conspirator, Target, Accomplices, IsRunning, IsPaused, IsEnded and Result (Success, Failed or None). Conspirator and Target read as null, and Accomplices as empty, when the scheme does not run.

On the scheme’s runner (scheme.SchemeRunner, namespace MrW.Intrigues.Graph).

Signature What it does
bool AddAccomplice(Actor actor) Makes the actor an accomplice. false for nobody, an actor not in the game, the conspirator, the target or an accomplice already there.
bool RemoveAccomplice(Actor actor) Takes the actor out. false when they are not one.
bool IsAccomplice(Actor actor) True for an accomplice.
ActorList Accomplices The built-in Accomplices list, in the order they joined.

When someone joins, Actor.onJoinedScheme and SchemeRunner.onAccompliceJoined fire, then the scheme’s On Accomplice Joined nodes run. Actor.onLeftScheme gives an AccompliceExit: Removed, Died, Destroyed or SchemeEnded.

Signature What it does
static void IM.Trigger(Scheme scheme, string triggerName, bool value = true) Fires a scheme trigger. Wait For Trigger nodes listen to IM.onTrigger.
void Actor.Trigger(string triggerName, bool value) Sends a trigger to one actor, raising its OnTrigger.

On a client, both go to the host when a way to send them exists. IM.Trigger needs a run the host’s records brought, or it is not sent.

IM.onSchemeStarted and IM.onSchemeEnded report any scheme. IM.onSchemeChanged reports something about a run: a pause, a new objective, new accomplices, a result. The conspirator’s own onSchemeStarted, onSchemeLoaded and onSchemeEnded are on Actor. A start is not announced for a scheme restored from a save. Events reference has the full list.

What you see Why What to do
StartScheme returns null The actor is the target, the scheme already runs against that target, it is unknown or has no graph, or a requirement is unmet. Ask CanStart first and read GetReasons.
IM.Meets is false and logs one warning The set name is unknown. Check the set’s name or ID.
A check logs one error and answers “not met” It ran off the main thread. Call it from the main thread.
AddAccomplice is false The actor is the conspirator or the target, is already in, or is not in the game. Check the cast.