playMaker

Author Topic: Playmaker Events from script and EventTarget/Data.  (Read 9889 times)

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Playmaker Events from script and EventTarget/Data.
« on: December 16, 2013, 09:02:18 AM »
Hi,

i would like to propose some changes to the event interface accessible from script/custom actions.

It should be made crystal clear that if u want to use Playmaker Events from your script u have to use the "PlayMakerUtils.SendEventToGameObject" calls and not the public accessible calls for PlaymakerFSM/Fsm classes.

Thats because they assume a valid set EventTarget and correctly set global eventdata. I did use the none "PlayMakerUtils" calls for some custom actions/scripts and we did run in all sorts of problems, especially if u even try to delay the send calls via custom systems like the UFPS vp_timer.

The reason is the way the system handles the EventTarget/EventData if not used by the correct call or if u don't fully understand what to set when and why.

So maybe u could add some warnings or make the calls internal? Adding a explicit EventTarget parameter to the PlaymakerFSM.SendEvent() call would have also helped. The problem is that its not clear for a external user, that this easy accessible call will not use the FSM instance u just called the SendEvent() on, but always the EventTarget member at the time the event is processed().

thx Andy


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15563
  • Official Playmaker Support
Re: Playmaker Events from script and EventTarget/Data.
« Reply #1 on: December 16, 2013, 09:22:24 AM »
Hi,

It would be good to provide a detailed pseudo code, cause i am not sure what's not available already, so far i have always been able to direct events the way i wanted without any confusion. So a concrete example would help here, you may have a very good problematic for sure.

Bye,

Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Playmaker Events from script and EventTarget/Data.
« Reply #2 on: December 16, 2013, 10:06:53 AM »
I can't give u pseudo code, since its always a combination of sending events between FSM inside PM and external script code also communicating with a FSM.

I will try to detail the problem cases we run into.

1) We used Playmaker.SendEvent(string) to send events by default from script, assuming we would always send the event to the Fsm component we call the function on, as there is no parameter/hint on the code itself that would suggest otherwise.

The problem is this only works if u never use the "SetEventTarget" action, which just notes "Sets the target FSM for all subsequent events sent by this state."

Whats actually missing is the check if a incoming fsm event, was actually send by this "fsm state" as stated in the tooltip, instead "this.Event(this.EventTarget, fsmEvent);" will always be used.

So if u setup a SetEventTarget in some states and also have script code sending events, the script code needs to clear the EventTarget or u might send the event to whatever is set at this time. While this seems fine, u need to-be aware of this or like in our case are up for quite some debugging.


2) The other problem was this: How can u correctly send a delayed FsmEvent from script if u are not aware of the way EventData is handled inside DelayedEvent().Update().

I naively used a vp_timer() from the UFPS package, in conjunction with setting eventdata. This ofc will fail, if u interleave PM and script event data sets and not correctly emulate what DelayedEvent().Update() is doing.


Thats why using the "SendEventToGameObject" version is safer, since it handles the EventTarget + EventData correctly in all cases. The problem was, that i did not look for a "PlayMakerUtils" namespace, since i found the SendEvent/Event calls easily.

The only oddity is the "Fsm.SetEventDataSentByInfo()" call, that will always be called, no matter what event source was used?
It seems u cant override this logic, since if u send a event from script, those members should be null/unset. This can only be solved by manually calling ProcessEvent(), with a correctly setup EventData object, which seems like a bad idea.

So a version like this is missing to handle all this correctly:
Code: [Select]
public void Event(FsmEventTarget eventTarget, FsmEvent fsmEvent, FsmEventData eventData);

U could than also wrap this around some extension methods, to correctly set the EventDataSentByInfo inside FsmEventData.

bye Andy
« Last Edit: December 16, 2013, 10:24:31 AM by Andy22 »