playMaker

Author Topic: Firing event from script  (Read 5664 times)

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Firing event from script
« on: May 15, 2013, 06:19:48 AM »
I watched this video and try to make sample and test

http://www.screencast.com/users/JeanFabre/folders/PlayMaker/media/69f1ce74-69aa-4969-aeb6-904fe6427e4b

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker ;

public class test11 : MonoBehaviour {


public string fsmInterfaceName = "FsmScriptInterface";
private PlayMakerFSM fsmInterface;

void Start () {
PlayMakerFSM[] temp = GetComponent<PlayMakerFSM >();
foreach (PlayMakerFSM fsm in temp) {
if(fsm.FsmName  == fsmInterfaceName ){
fsmInterface = fsm;
break;
}
}

AndroidPurchases.Load ();
if(AndroidPurchases.HasPurchased("test11")){
fsmInterface.Fsm.Event("DONE");
}
}

void Update (){
if(AndroidPurchases.HasPurchased("test11")){
fsmInterface.Fsm.Event("DONE");
}
}}

But i still get error while compile this stuff. 
Do you guys have anyother idea to solve this problem?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Firing event from script
« Reply #1 on: May 15, 2013, 08:22:26 AM »
Hi,

 Quite a few things here:

1: you need to use "getcomponents" with an "s" to get a list of component
2: your class definition had bad {} layout, so it was corrupted.
3: if it would compile, you would get the "DONE" event fired all the time, where instead, you only need to fire that event once, so I modified it
4: why do you need to use the technic of listing all playmaker fsm? do you have a particular need or setup? basically I would recommand to use a public var instead and simply drag the fsm on it ( if there is only one, then you can drag the gameObject directly, else you need to drag the fsm component in question.)
5: if you want to verify purchases, then why don't you make a custom action, it will be more efficient and flexible.


Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker ;

public class test11 : MonoBehaviour {


public string fsmInterfaceName = "FsmScriptInterface";
private PlayMakerFSM fsmInterface;

private bool done;

void Start () {
PlayMakerFSM[] temp = GetComponents<PlayMakerFSM>();
foreach (PlayMakerFSM fsm in temp) {
if(fsm.FsmName  == fsmInterfaceName ){
fsmInterface = fsm;
break;
}
}
if (fsmInterface==null)
{
Debug.LogError("Interface not found");
}

AndroidPurchases.Load ();
IsItDone();
}


void Update (){
IsItDone();
}

void IsItDone()
{
if( AndroidPurchases.HasPurchased("test11") && fsmInterface!=null && !done ){
done = true;
fsmInterface.SendEvent("DONE");
}
}
}

 Bye,

 Jean

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Firing event from script
« Reply #2 on: May 15, 2013, 10:51:53 AM »
Thank you very much Jean

Actually I've studied  programming for 2,3 months.

Recently with Play maker and  just a little code stuff, I finished my project. 

But problem has occurred when i'm trying to attach InAppBilling stuff.

I finished attaching managed items code with "get property" and "set property".
So when item has been purchased i can get sign from code and lead that value into my playmaker FSM.

but with unmanaged item. Code and setting is done. now i can purchase unmanaged item.

with unmanaged item, which is consumable, i need to get global even to changing playerprefs value.

This is why i'm trying to make let code fire event. 

As you  advise, i will do research on public  var.

Custom action stuff, i'm not sure that i  can make it or not. 

Anyway, I always thanks to you and playmaker :)