Forum rules - please read before posting.

Two outputs for custom Action

edited January 2019 in Technical Q&A

Hi,

I was wondering if there's a way for a custom Action to have two outputs.

By default a custom Action only has one output - After Running, and this allows you to drag the arrow to another Action.

What I would like to have, is to get my Action to return two outputs, pretty much what happens when you check a bool through Variable:Check.

So instead of After running, the Action would have If condition is met: and If condition is not met:, allowing me to drag two different arrows from my custom Action.

Is there any chance to achieve this? Thanks!

Comments

  • Derive your custom Action from ActionCheck - that'll give you two outputs.

    See the provided ActionCheckTemplate file - it includes comments on how to use the CheckCondition method that determines which output is followed when the Action is run.

  • Thank you, I should be able to work something out with this!

  • After playing around with this for a bit, I ended up using a normal custom action, but I changed a few things to get the two outputs.

    I tried deriving my custom action from ActionCheck, but that was quite complicated. Following ActionCheckTemplate and merging it into the normal custom action seems to be working well though.

    Here's how I did it, in case someone finds it useful, or if anything, maybe mistakes can be pointed out:

    Public class needs to derive from ActionCheck, instead of usual Action, so it's something like this at the top of the custom action:

    namespace AC
    {
    
        [System.Serializable]
        public class AgentSend : ActionCheck
        {
    

    Where you usually set the category, title and description, I added numSockets =2;It looks like this:

    public CustomAction ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Character;
                title = "Custom Action";
                description = "Your custom description.";
    
                numSockets = 2;
            }
    

    One final thing, after Run() function I added:

    public override bool CheckCondition()
            {
                // Return 'true' if the condition is met, and 'false' if it is not met.
    
                if (AC.GlobalVariables.GetBooleanValue(7) == false) // Check against your custom bool
                {
                    Debug.Log("It's false"); // Whatever happens if the action returns false
                    return false;
                }
                else
                {
                    Debug.Log("It's true"); // Whatever happens if the action returns true
                    return true;
                }
            }
    

    This determines what happens if your custom bool is true or not.

    All of this seems to do the trick.

    The only thing is that it seems this custom action has one extra field that isn't normally there on native Actions with two outputs:

    (After running: isn't usually there and you should see If conditions is met/ not met only, but it works fine if set to Skip)

    The After running: doesn't seem to be a problem unless there's some kind of performance issue that I'm not aware of.

  • Remove the AfterRunning() function call at the end of your ShowGUI function.

  • Removing AfterRunning() makes it a lot easier to read now!

    I'm sorry to be such a pain, you have been mega helpful! Thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.