playMaker

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

zhuxianzhi

  • Playmaker Newbie
  • *
  • Posts: 5
How do I send custom data to PlayMakerFSM?
« on: August 04, 2017, 03:08:29 AM »
I would like to send some custom data when two game objects collide.


Code: [Select]
        private void TryDoAttack(Collider2D collider2D)
        {
            var targetFsm = collider2D.gameObject.GetComponentInParent<PlayMakerFSM>();

            if (targetFsm != null)
            {
                //    targetFsm.Fsm.GetFsmObject("");   //Send custom data
                targetFsm.SendEvent("Beaten");
            }
        }

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #1 on: August 04, 2017, 03:34:12 AM »
Hi,

 For this you have two options ready made.

1:

 before you send the FsmEvent, setup HutongGames.PlayMaker.Fsm.EventData

create a new EventData, fill data ( string, int, etc etc), and assign it to HutongGames.PlayMaker.Fsm.EventData, it's a static property so it affects everything ( that's why you need to set it one line before sending the event.

with this you can them use GetEventInfo action as usual.

2: If your data is complex, typically with several ints or floats, you can use PlayMaker Utils ( from the Ecosystem, you may already have it).

this time you set SetEventProperties.properties, and fill it with keyValue pairs like:

SetEventProperties.properties["My Value"] = something;

then you use GetEventProperties action to retrieve "My Value" and save it into an Fsm variable

Let me know if you have more questions.


 Bye,

 Jean

zhuxianzhi

  • Playmaker Newbie
  • *
  • Posts: 5
Re: How do I send custom data to PlayMakerFSM?
« Reply #2 on: August 06, 2017, 10:20:09 PM »
Hi,

 For this you have two options ready made.

1:

 before you send the FsmEvent, setup HutongGames.PlayMaker.Fsm.EventData

create a new EventData, fill data ( string, int, etc etc), and assign it to HutongGames.PlayMaker.Fsm.EventData, it's a static property so it affects everything ( that's why you need to set it one line before sending the event.

with this you can them use GetEventInfo action as usual.

2: If your data is complex, typically with several ints or floats, you can use PlayMaker Utils ( from the Ecosystem, you may already have it).

this time you set SetEventProperties.properties, and fill it with keyValue pairs like:

SetEventProperties.properties["My Value"] = something;

then you use GetEventProperties action to retrieve "My Value" and save it into an Fsm variable

Let me know if you have more questions.


 Bye,

 Jean

感谢回复,第二种方式我不是很明白,请问可以可以写一点代码实例吗

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #3 on: August 07, 2017, 10:23:30 AM »
Hi,

 Ok, I'll write a quick sample on this and actually do a wiki page on this, this will be better.

Bye,

 Jean

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #4 on: March 27, 2020, 08:59:01 AM »
Hi,

Is there a sample code about SetEventProperties.properties now ?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How do I send custom data to PlayMakerFSM?
« Reply #5 on: March 27, 2020, 04:07:26 PM »
Hi

Maybe the Playmaker API can Help

neteeyore@comcast.net

  • Playmaker Newbie
  • *
  • Posts: 9
Re: How do I send custom data to PlayMakerFSM?
« Reply #6 on: March 27, 2020, 11:00:36 PM »
I would also be interested in a better understanding of the second option that Jean was describing.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #7 on: March 30, 2020, 02:25:16 AM »
Hi,

 What is it that doesn't work on your end based on what I wrote?

Bye,

 Jean

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #8 on: March 30, 2020, 07:18:51 AM »
Hi,

 What is it that doesn't work on your end based on what I wrote?

Bye,

 Jean

In the https://hutonggames.fogbugz.com/default.asp?W127 section I don't found any example using :
Code: [Select]
SetEventProperties.properties["My Value"] = something;Please help me to give a hint if there is a example for it there.

Or can you just write a short example code for example how to send a int value with a key ? (And we can recive the value using GetEventProperties action)

Thank you !

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #9 on: April 03, 2020, 02:35:26 AM »
Hi,

 you need to fire a playmaker event, are you doing this? meaning inside the playmaker fsm, you check for the event and use GetEventProperties then?

Bye,

 Jean

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #10 on: April 03, 2020, 03:11:10 AM »
Hi

I know it need to fire a event , but I'm not fimilar with C# so I can not figure out how to writre the script correctly .
So it will help if there is a sample code , or can you help me correct the code below to send a int ?

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

public class MyBehaviour : MonoBehaviour
{
    public PlayMakerFSM fsm;
    public int AAA;

    void Update()
    {
        // i don't know how to use it
        SetEventProperties.properties["DATA1"] = AAA;

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


« Last Edit: April 03, 2020, 03:14:04 AM by Hayato »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #11 on: April 03, 2020, 03:44:26 AM »
Hi,

 yes, that's right, that's all you need.

 in fsm, you use GetEventProperties and get the value for key "DATA1"

but if you want to send a value every update, then you are better off setting an FsmString on that fsm directly, since you already have a pointer to it.

Bye,

 Jean

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #12 on: April 03, 2020, 01:21:12 PM »
Hi,

 yes, that's right, that's all you need.

 in fsm, you use GetEventProperties and get the value for key "DATA1"

but if you want to send a value every update, then you are better off setting an FsmString on that fsm directly, since you already have a pointer to it.

Bye,

 Jean

The code what I write have error in console , it says:

Code: [Select]
Assets\SendToFSM.cs(13,9): error CS0103: The name 'SetEventProperties' does not exist in the current context
So I think it's not correct , but don't know how to correct it .
Can you give more hint about it ?
Thank you !

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I send custom data to PlayMakerFSM?
« Reply #13 on: April 08, 2020, 02:22:20 AM »
Hi,

 Do you have the SetEventProperties action in your project?

Bye,

 Jean

Hayato

  • Playmaker Newbie
  • *
  • Posts: 36
Re: How do I send custom data to PlayMakerFSM?
« Reply #14 on: April 09, 2020, 04:41:30 AM »
Hi,

 Do you have the SetEventProperties action in your project?

Bye,

 Jean

Hi jean,

Yes, I install PlayMakerUtils package via ecosystem and both SetEventProperties and GetEventProperties can see in actions broswer .

---
PlayMaker: 1.9.0.p20
Unity: 2019.3.7f1
Build Target: StandaloneWindows