playMaker

Author Topic: Custom event is not fired the first time is raised  (Read 4727 times)

DaniM

  • Playmaker Newbie
  • *
  • Posts: 4
Custom event is not fired the first time is raised
« on: April 29, 2011, 08:12:57 AM »
Hi, we've just bought PlayMaker few days ago (fantastic tool btw), and we are having a little problem with the custom events.
We haven't found any mention to it, so here is the case:

I have simple FSM (3 states) which one of the transitions is done by firing a custom event (say "MYEVENT"). Something like this:

State A (MYEVENT)-> State B (FINISHED)-> State C

I raise this custom event by code, like this

Code: [Select]

//method's code
...
//fsm is a PlayMakerFSM field on a MonoBehaviour component
fsm.Fsm.Event("MYEVENT");

But the change of the state never happens, so i have to put a "patch" in the MonoBehaviour's Update that seems like...

Code: [Select]

//...somewhere in the Update
if(fsm.ActiveStateName == "State A" && myCustomEventIsAlreadyFired)
{
       //relaunch the event
       fsm.Fsm.Event("MYEVENT");
}


And with that, the transition is done.


I've got the impression that the first time MYEVENT is rised, is like the event was "cached", and the second time is when its really fired.

The complete code is very simple and the fsm is alright (with the "patch" it works perfectly), so, am i doing something weird? have the customs events some restrictions that the "built-in"s not? is there any way to avoid that ugly "if"?

Thanks in advance, and thanks for this useful tool.

PD: Apologize for my bad english (is not my mother tongue), and sorry if i sound disrespectful.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Custom event is not fired the first time is raised
« Reply #1 on: April 29, 2011, 08:23:19 AM »
Hi,

 don't worry, you do not sound dis respectful or anything :)


 What action are you actually using to trigger the custom event and whyt action are you editing? I never experience any problems with events firing, none, so hopefully this is just a misunderstanding or something.

 Bye,

 Jean


DaniM

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Custom event is not fired the first time is raised
« Reply #2 on: April 29, 2011, 08:43:02 AM »
Thanks for the quick reply!

Well, actually im not using any action to trigger the event this time (i have some -probably- silly reasons to not use it), im doing it like the doc's page:

https://hutonggames.fogbugz.com/default.asp?W329

The "call-stack" is:
- Some HighLevel (like a level manager) MonoBehaviour's method()->
- Here i get the object (MonoBehaviour too) that has the fsm, and call its method "methodThatRaiseTheEvent()"->
- Inside it, is where i've got the
Code: [Select]
fsm.Fsm.Event("MYEVENT");

it is alright? will it be better if i use an action? or in other words, have i to use an action?

Thanks again!

EDIT:

Actually is not a stupid reason trying to not use an action, my intial state is like a "waiting/idle" state that does nothing until the event is triggered.
« Last Edit: April 29, 2011, 08:47:42 AM by DaniM »