playMaker

Author Topic: Send event from script  (Read 2164 times)

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Send event from script
« on: July 18, 2016, 07:05:12 AM »
Hi there,

I have an event called "SplitString" (it is global), in my script i referenced the fsm by making it public and then dragging it on the the field. and I do the the following myFsm.SendEvent("SplitString");

however that does not work.. Am I missing something??

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send event from script
« Reply #1 on: July 18, 2016, 10:04:59 AM »
Hi,

 Several possible issues:

1: typo. The event name isn't exactly as the string you define in your code.
2: the event is not in a transition of the current active state or not set as a global transition on some state in that fsm.
3: MyFsm isn't pointing to what you think, debug the name of the fsm, the activestatename before sending so you know where you are.
4: do you get errors in the console?
5: is your gameobject disabled, or is it an actual prefab, and not an instance of it.

Bye,

 Jean

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Send event from script
« Reply #2 on: July 18, 2016, 11:22:36 AM »
Name is exactly the same, and it's a global transition on that specific FSM on a state. (I'm testing this on iOS)

The thing is that If I move this to a different location, it works. but in this bit here it doesn't..

So if I move to beginning of this function then it WORKS:

Code: [Select]
public void StartRecording() {
// We then start recording, with three possible inputs: "first", "second", and "third"
Debug.Log (FSM_Input);
Debug.Log ("Starting recording");
startRecording (FSM_Input); // START RECORDING HERE (HOLD BUTTON)

// Three seconds later, we wiĺl stop recording in the provided onRecordingDone function
if (stopped)
return;

}

However, if I move it here, then it doesn't work anymore...


Code: [Select]
public void resultCallback(string status) {
#elif UNITY_ANDROID || UNITY_STANDALONE_OSX
public static void resultCallback(int score, int speed, string words) {
#endif
// Callback when result is available, a few seconds after stopRecording, typically.
// See docs on how to parse the result.
Debug.Log ("Result");
#if UNITY_IOS
FsmString result_iOS = FsmVariables.GlobalVariables.FindFsmString("result_iOS");
result_iOS.Value = status;
myFSM.SendEvent ("SplitString");
Debug.Log (status);
Debug.Log("result_iOS =" + result_iOS.Value);

What I'm trying to achieve is that each time the recording stops and result comes back in string, I need to send event to that FSM to let it know that the result has came back and then to split the string, and select the first index out of that array. So once I have the score (first item of string result) I can pass it on to ugui text.

But the event won't fire for some reason, I've put debug logs in playmaker and they dont show up so I assume that the event doesn't fire up..

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send event from script
« Reply #3 on: July 22, 2016, 03:47:15 AM »
Hi,

Are you debugging the line where you make the call or the fsm that shoudl receive the event?

 If I understand you correctly, moving the same code in different places in your logic make it work, which seems to indicate that it's not a problem with the function but just a race condition where your object may not be yet ready. Are you instantiating the GameObject supposed to receive the event at the same time that you send the event? Maybe you should wait a frame then.

Bye,

 Jean