playMaker

Author Topic: Call Static with callback parameters[SOLVED]  (Read 1741 times)

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Call Static with callback parameters[SOLVED]
« 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);
« Last Edit: August 01, 2018, 02:37:03 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Call Static with callback parameters
« Reply #1 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

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Call Static with callback parameters
« Reply #2 on: July 30, 2018, 09:52:03 PM »
no. I did a workaround in my case, but I would like to know how!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Call Static with callback parameters
« Reply #3 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

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Call Static with callback parameters
« Reply #4 on: July 31, 2018, 09:12:54 PM »
Got it, thanks.