Call my C# from a scheme
The goal
Section titled “The goal”A rule that is awkward to draw as nodes lives in your C#, and a scheme calls it.
Do it, step by step
Section titled “Do it, step by step”- Write a method and mark it
[IntrigueMethod]. The return type decides what it is:
| Returns | Used by |
|---|---|
void, bool or bool? |
Run Code. void counts as yes once it ran. null is no answer. |
Actor, (Actor, Actor), Clan or Family |
Get From Code |
A list of actors (IEnumerable<Actor>) |
the group From a method in code of Find Actor, For Each Actor and the other actor groups |
- Let Unity compile the script.
- In the scheme, add Run Code and pick the method in Method. Link True, False and No Answer. For a method that gives something back, add Get From Code, pick the method in Method Name, which sets Gives, and set Store In. Link Found and Not Found. With Gives on Two actors, set Store Second In too and link Both Found, Only First, Only Second and None Found.
- For shows for a method that takes one actor, two actors or an
IntrigueCall. Against shows for two actors or anIntrigueCall. For starts as the Conspirator and Against as the Target.
The demo’s DemoMethods.cs shows both kinds. These lines are copied from it, bodies left out:
[IntrigueMethod(Description = "The living head of the highest rank in the world (the high king when there is one), or nobody.", ReadsOnlyIntrigues = true)]public static Actor HighestRuler()
[IntrigueMethod(Description = "The living man-at-arms of the conspirator's clan with the most Arms (knights and captains first), or nobody.", ReadsOnlyIntrigues = true)]public static Actor StrongestKnight(Actor conspirator)Example. Compiled against the package’s runtime assembly; not run in Unity. A check of your own. The class name and the method name are yours.
using MrW.Intrigues;
public static class MyMethods{ [IntrigueMethod(Description = "True when the conspirator is older than the target.", ReadsOnlyIntrigues = true)] public static bool? IsOlder(Actor conspirator, Actor target) => conspirator == null || target == null ? (bool?)null : conspirator.Age > target.Age;}A method that is not static
Section titled “A method that is not static”An instance method needs an object to answer. Give it one with IntrigueMethods.Register(host). Without that, the one active and enabled object of that class in the loaded scenes answers, if the class is a MonoBehaviour.
What you will see
Section titled “What you will see”Run Code goes through True when the method says yes, through False for no, and through No Answer when the method answers null, throws or cannot be called. A throw is logged. Get From Code puts what it got into Store In and goes through Found. When nothing is found, it empties that variable and goes through Not Found.
What can go wrong
Section titled “What can go wrong”- The Studio does not list the method. It must be in a class, not generic, and take one of these parameter lists:
(),(Actor),(Actor, Actor),(Scheme)or(IntrigueCall).IntrigueMethods.LeftOutlists the marked methods that were left out, with the reason. - You need to return a number. A method cannot. The demo leaves the number in a World variable and answers true when it is above 0. Read the variable straight after Run Code.
- The method gives the wrong kind to Get From Code. It finds nothing, and the card warns.
- Link No Answer. Otherwise a broken method ends the flow at the node.
How it connects
Section titled “How it connects”- Parameters,
IntrigueCall,ReadsOnlyIntriguesand the list of reasons are on Code methods: [IntrigueMethod]. - The nodes are Run Code and Get From Code.
- What your own code must respect is on Rules for code that touches Intrigues.