Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: imtrobin on July 30, 2018, 03:19:08 AM

Title: Call Static with callback parameters[SOLVED]
Post by: imtrobin on July 30, 2018, 03:19:08 AM
Hi, I have a static function defined as so, I set the Call Static parameters is Object, playmaker says


"Invalid Method name or Parameters."

 public static void Test (Action <bool> callback);
Title: Re: Call Static with callback parameters
Post by: jeanfabre on July 30, 2018, 06:00:36 AM
Hi,

Uhm, that might be because of the Action type. You'll need to make a custom for this, do you know how to do that?

 Bye,

 Jean
Title: Re: Call Static with callback parameters
Post by: imtrobin on July 30, 2018, 09:52:03 PM
no. I did a workaround in my case, but I would like to know how!
Title: Re: Call Static with callback parameters
Post by: jeanfabre on July 31, 2018, 03:39:50 AM
Hi,

Here we go:

Code: [Select]
using UnityEngine;
using System;

namespace HutongGames.PlayMaker.Actions
{
    public class TestStaticCallback : FsmStateAction
    {
/// <summary>
/// The result of the TestStaticCallbackClass.Test() callback
/// </summary>
        [UIHint(UIHint.Variable)]
        public FsmBool Result;

        public override void OnEnter() // when the action starts.
        {
TestStaticCallbackClass.Test(HandleAction); // that's the call to the static
}

/// <summary>
/// Handles the action callback from TestStaticCallbackClass.Test()
/// </summary>
/// <param name="obj">If set to <c>true</c> object.</param>
        void HandleAction(bool obj)
        {
            Result.Value = obj; // we set the value of the callback into the Fsm bool variable.

Finish(); // We tell PlayMaker that the action is done ( when all actions are done in a state, FINISH transition is call)
        }

    }

/// <summary>
/// This is the class that implements a static method with an Action Callback, right now it's synchronous,
/// But it could fire later on after several frames or seconds ( could be calling a web server for example)
/// </summary>
    public static class TestStaticCallbackClass
    {
        public static void Test(Action<bool> callback)
        {
            callback.Invoke(true);
        }
    }
}

Let me know if you have questions.

Bye,

 Jean
Title: Re: Call Static with callback parameters
Post by: imtrobin on July 31, 2018, 09:12:54 PM
Got it, thanks.