playMaker

Author Topic: Custom Action needs to use Send Event  (Read 5076 times)

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Custom Action needs to use Send Event
« on: May 30, 2012, 06:45:53 PM »
I'm trying to utilize the send event to game object with FSM Name and event name, but having some issues trying to initialize everything through code.

I need to utilize this in a for each loop for a dynamic number of elements, so I have to do it via custom action.

Here is the code I have so far:
Code: [Select]
FsmString targetFsmName = new FsmString(); targetFsmName.Value = "Got Hit FSM";
FsmGameObject translationStep1 = new FsmGameObject(); translationStep1.Value = goTheCollidingUnit;
FsmOwnerDefault translationStep2 = new FsmOwnerDefault(); translationStep2.GameObject = translationStep1;
FsmEventTarget theTargetUnitFSM = new FsmEventTarget(); theTargetUnitFSM.gameObject = translationStep2; theTargetUnitFSM.fsmName = targetFsmName;

What am I missing before I can fill all the info I need into:
Code: [Select]
Fsm.Event(eventTarget, sendEvent);
I think I'm just missing a FSMEvent, but how do I create this via code?

I've attached an example image of exactly what I'm trying to achieve if it were to be done via the Playmaker GUI.
« Last Edit: May 30, 2012, 06:56:30 PM by Disastercake »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: Custom Action needs to use Send Event
« Reply #1 on: May 31, 2012, 03:14:46 PM »
You can get an FsmEvent using the event name:

FsmEvent fsmEvent = FsmEvent.GetFsmEvent(fsmEventName);

Or just send the event as a string:

Fsm.Event(eventTarget, fsmeEventname);

The former is better for performance if you're going to store and send the same event again.

Are you using a code editor with intellisense? E.g., Visual Studio. This makes it a lot easier to work with any API, since you can see methods, parameters etc. as you type...

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Custom Action needs to use Send Event
« Reply #2 on: May 31, 2012, 06:36:44 PM »
The default unity script editor has intellisense I believe, but I'm pretty new to coding ,so I'm getting use to how to read what pops up.  Thanks for helping me out! =D  Do you recommend using Visual Studio to write the scripts instead of MonoDevelop?
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Custom Action needs to use Send Event
« Reply #3 on: May 31, 2012, 07:07:44 PM »
Now I' having issues getting the FSMEventTarget to work correctly.  Am I missing any code in this to set it up right?

Code: [Select]
FsmString targetFsmName = new FsmString(); targetFsmName.Value = "Got Hit FSM";
FsmGameObject translationStep1 = new FsmGameObject(); translationStep1.Value = goTheCollidingUnit;
FsmOwnerDefault translationStep2 = new FsmOwnerDefault(); translationStep2.GameObject = translationStep1;
FsmEventTarget theTargetUnitFSM = new FsmEventTarget(); theTargetUnitFSM.gameObject = translationStep2; theTargetUnitFSM.fsmName = targetFsmName;
theTargetUnitFSM.
FsmEvent fsmEvent = FsmEvent.GetFsmEvent("Got Hit");
Fsm.Event(theTargetUnitFSM, fsmEvent);

This type of information should be in the docs somewhere.  I imagine that creating your own event call in code can just be a reusable code segment that people can copy and paste and use their own variables.  Usually I can just look at other actions for examples, but there is nothing in the examples that shows how to instantiate the required objects for a send event method.
« Last Edit: May 31, 2012, 09:16:14 PM by Disastercake »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Custom Action needs to use Send Event
« Reply #4 on: June 01, 2012, 12:04:09 AM »
I ended up finding this function and used it with successful results:

Fsm.SendEventToFsmOnGameObject(GameObjectToTrigger, "FSM NAME", "EVENT NAME");

Is there a downside to using this function?  I feel that the syntax for the parameters are much easier to understand than the one I was trying to deal with in above posts.  Dealing with FSM Objects really complicates things.
« Last Edit: June 01, 2012, 12:24:15 AM by Disastercake »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: Custom Action needs to use Send Event
« Reply #5 on: June 01, 2012, 02:53:31 PM »
That's probably the simplest solution.

There's 2 versions of that function. One takes a string event name, the other takes an FsmEvent. If you're going to send the event quite often it would be better to get the FsmEvent, store it, then send that.