playMaker

Author Topic: How do I send custom data to PlayMakerFSM?  (Read 5448 times)

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #15 on: April 09, 2020, 05:06:54 AM »
Okay finally I got the answer,  it do not need :
Code: [Select]
//using HutongGames.PlayMaker;
//using HutongGames.Utility;

but need to add  :
Code: [Select]
using HutongGames.PlayMaker.Actions;
The full sample code send a int with key that work to me is:

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker.Actions;

public class SendToFSM : MonoBehaviour
{
    public PlayMakerFSM fsm;
    public int AAA;
   
    void Update()
    {
        // Set variables with key
        SetEventProperties.properties["DATA1"] = AAA;

        // sending an event
        fsm.SendEvent("myEvent");
    }
}

The function is really powerful ! : )
« Last Edit: April 09, 2020, 05:23:31 AM by Hayato »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: How do I send custom data to PlayMakerFSM?
« Reply #16 on: April 10, 2020, 06:11:28 AM »
SetEventProperties.properties["My Value"] = something;

I might be wrong here but this sounds a lot like a Hash Table pair, name:value.
Which makes me wonder, out of curiosity, if I missed something here, like being able to directly input a key and its value into an event instead of having to save the name as a string on one side, and its associated var on the other.

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #17 on: April 10, 2020, 06:32:23 AM »
SetEventProperties.properties["My Value"] = something;

I might be wrong here but this sounds a lot like a Hash Table pair, name:value.
Which makes me wonder, out of curiosity, if I missed something here, like being able to directly input a key and its value into an event instead of having to save the name as a string on one side, and its associated var on the other.

Do you mean ways like the image attached below ?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: How do I send custom data to PlayMakerFSM?
« Reply #18 on: April 13, 2020, 07:11:58 AM »
Something like that, yes.
It would have to combine this code above that creates custom properties to be set into an event, with a basic action that gets a key + value at a given index from a Hash Table.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #19 on: April 14, 2020, 01:14:39 AM »
Hi,

 it's then likely because you are not including the namespace for it at the top of your script:

using HutongGames.PlayMaker.Actions;


normally your ide where you edit scripts should give you some hints that it is necessary and even do it for you. I use Rider myself and did not look back.

Bye,

 Jean


Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #20 on: April 14, 2020, 07:00:52 AM »
Hi,

 it's then likely because you are not including the namespace for it at the top of your script:

using HutongGames.PlayMaker.Actions;


normally your ide where you edit scripts should give you some hints that it is necessary and even do it for you. I use Rider myself and did not look back.

Bye,

 Jean

Like some of PlayMaker users ,I don't fimiliar with both C# and IDE , even don't know clearly about namespace meaning before the problem ,that's the reason why I want to get a full sample code to learn how to use the function .

Thank you for make sure that my code is correct , or in my own knowledge it's impossiable to go to the next step that IDE adventitiously help me.  :)


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #21 on: April 15, 2020, 01:56:37 AM »
Hi,

 ok, I have made a new sample on the Ecosystem called "SetFsmFloatVariableValue", get that and check the script "SetFsmFloatVariableValue" in the scene "SetFsmFloatVariableValue", it will show you how to properly set the value of an fsm variable.

here's the code:

Code: [Select]
using HutongGames.PlayMaker;
using UnityEngine;

public class SetFsmFloatVariableValue : MonoBehaviour
{

public PlayMakerFSM Fsm;

public string FsmFloatVariableName = "My Fsm Float";
public float SetFsmFloatValue;

private FsmFloat _fsmFloatVariable;

void Start () {
if (Fsm == null)
{
Debug.LogError("Missing Fsm reference");
return;
}

_fsmFloatVariable = Fsm.Fsm.GetFsmFloat(FsmFloatVariableName);

if (_fsmFloatVariable == null)
{
Debug.LogError("<"+FsmFloatVariableName+"> could not be found in Fsm");
return;
}

SetValue();
}

// Update is called once per frame
void Update ()
{
SetValue();
}

void SetValue()
{
if (_fsmFloatVariable != null)
{
_fsmFloatVariable.Value = SetFsmFloatValue;
}
}
}


Bye,

 Jean