Skip to content

Writing a CustomAgent class

Hippolippo edited this page Oct 17, 2022 · 2 revisions

Making a CustomAgent Class

An Agent is what handles the logic of a node. This class will handle the inputs and set the outputs and will have methods called when command ports are activated:

To begin, create a class that extends PlasmaModding.CustomAgent

public class ExampleNode: PlasmaModding.CustomAgent
{
}

If you have code that you want to run when the node is first created, override the OnSetupFinished() method with what you want to happen:

protected override void OnSetupFinished()
{
   // code for when node is created
}

To define a function that will be called when a command port is activated, create a function with the attribute [SketchNodePortOperation(α)] where α is the int you passed into the operation parameter when creating the port using PlasmaModding.CustomNodeManager.CreateCommandPort:

[SketchNodePortOperation(α)]
public void AppropriateFunctionName(Behavior.SketchNode node){
   // code for when command port α is activated
}

You will often find yourself wanting to read from property nodes and write to output nodes. To get a property, use GetProperty(string) to get a property and WriteOutput(string, Behavior.Data) to write data to an output port.
Note that GetProperty returns an AgentProperty, to get the Data from the property, do AgentProperty.GetValue()


Example CustomAgent Class:

public class ExampleNode: PlasmaModding.CustomAgent
{
    protected override void OnSetupFinished()
    {
       // This function doesn't have to be here but if you want to do something when the node loads it goes here
    }

    [SketchNodePortOperation(1)]
    public void Called(Behavior.SketchNode node)
    {
        WriteOutput("Output Text", GetProperty("Text").GetValue());
    }
}
Clone this wiki locally