playMaker

Author Topic: Enum index resetting to 0 at runtime[SOLVED]  (Read 1626 times)

Dakk

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 21
Enum index resetting to 0 at runtime[SOLVED]
« on: February 13, 2020, 02:23:20 PM »
I use the "call method advanced" PM action to call all my analytics events that are in a C# script from Playmaker FSM actions often that reside in templates.

I create a global obj variable of the C# script on start- and use that global var to call the events from various game objects, often templates.  This all works perfectly when I pass strings as parameters to the C# script for the analytic event names. 

Yesterday- in an attempt to avoid typos, I switched the parameter of the C# script method from a string to an enum list.  The Call Method advanced action very nicely displays my enum list as a drop down list within the action - slick!  But after setting the correct enum in the Call Method Advanced action, at runtime it will switch to the first item in the enum list instead of retaining the one I set.   Is this something to do with reflection, or global obj variables that I don't understand?  Any one come across this?

code snippet of the c# script I am calling, works fine when a string is used instead of the enum list:

Code: [Select]

    public enum playerIAP_EventsEnum
    {
        IAP_ButtonPress,
        IAP_PurchaseSuccess,
        IAP_PurchaseFail,
        IAP_BankOpened,
        IAP_BankClosed,
        IAP_SpecialOfferDisplayed,
        IAP_SpecialOfferClosed
    }
    public void PlayerIAP_Events(playerIAP_EventsEnum EventName, string IAP_ID, float IAP_Price, int Level, string TransactionContext)
    {
        var request = new WriteClientPlayerEventRequest();
        string success = "Successful PFab Event";
        string FSM_Event = "success";
#if UNITY_ANALYTICS
        StoreType storeType = StoreType.Premium;
        switch (EventName)
        {
            case playerIAP_EventsEnum.IAP_ButtonPress :
                AnalyticsEvent.StoreItemClick(storeType, IAP_ID, null, new Dictionary<string, object>
                {
                    { "level", Level },
                    { "price", IAP_Price }
                });
                break;
            case playerIAP_EventsEnum.IAP_BankOpened:
                AnalyticsEvent.StoreOpened(storeType, new Dictionary<string, object>
                {
                    { "level", Level }
                });
                break;
            case playerIAP_EventsEnum.IAP_PurchaseSuccess:
                AnalyticsEvent.IAPTransaction(TransactionContext, IAP_Price, IAP_ID, null, Level.ToString(), null, null);
                break;
            default:
                AnalyticsEvent.Custom(EventName.ToString(), new Dictionary<string, object>
                {
                    { "level", Level },
                    { "iap_id", IAP_ID }
                });
                break;     
        }
#endif
#if PLAYFAB
        if (IsClientLoggedIn())
            {
                eventData = new Dictionary<string, object>()
                {
                {"iap_id", IAP_ID},
                {"iap_price", IAP_Price},
                {"level", Level},
                };
                request.Body = eventData;
                request.EventName = EventName.ToString();
                PlayFabClientAPI.WritePlayerEvent(request, result =>
            {
                RaiseCallbackSuccess(success, PlayFabAPIMethods.WritePlayerEvent, MessageDisplayStyle.none, FSM_Event);
                }, PlayFabErrorCallback);
            }
        else { Debug.Log("UserCustomEvents.cs ---  Playfab not logged in, won't send this event: " + EventName); }
#endif

#if FIREBASE_ENABLED    //  START FIREBASE ANLYTICS EVENT!!!!============================================================================----------------------------------------------
        Firebase.Analytics.Parameter[] iap_parameters = {
            new Firebase.Analytics.Parameter( "iap_id", IAP_ID)
            new Firebase.Analytics.Parameter( "iap_price", IAP_Price)
            new Firebase.Analytics.Parameter( "level", Level)
        };
        Firebase.Analytics.FirebaseAnalytics.LogEvent(EventName, iap_parameters);
#endif   //  END FIREBASE ANLYTICS EVENT!!!!============================================================================-------------------------------------------------

        //  START FACEBOOK EVENT!!!!============================================================================
        var fb_ae_parameters = new Dictionary<string, object>();
        fb_ae_parameters["iap_id"] = IAP_ID;
        fb_ae_parameters["iap_price"] = IAP_Price;
        fb_ae_parameters["level"] = Level;
        FB.LogAppEvent(EventName.ToString(), parameters: fb_ae_parameters);
        // End FACEBOOK EVENT!!!================================================================================

        if (debugLogEnabled) Debug.Log("PF and FB app events sent:  " + EventName + "  iap_id" + IAP_ID + "  iap_price: " + IAP_Price + " level: " + Level + "  TransactionContext: " + TransactionContext);
    }


Thanks in advance.
« Last Edit: February 19, 2020, 07:17:26 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum index resetting to 0 at runtime
« Reply #1 on: February 14, 2020, 06:17:31 AM »
Hi,

 but, if you can code, why use CallMethod action? just make a custom action calling it without any reflection, it will be better for perfs and sanity of the project.

Bye,

 Jean

Dakk

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 21
Re: Enum index resetting to 0 at runtime
« Reply #2 on: February 14, 2020, 12:25:53 PM »
Hi Jean,

Thanks for the response.  I have ~50 different analytic events and I don't want to hard code and edit and maintain actions to specifically call each event - every time I make a change during development I would need to edit both the code and the action.  I could just make an action that is the event with no external c# script (maybe what you are suggesting), but that would again be a lot of files to edit and maintain and would mean that I could not call the events from c#.   This is why the call method action is very nice- it is a single action that can set the params and call any event I need and I can have all my events in a single script.

I'm not concerned about performance as these events are infrequent in the actual scope of things, but yea the sanity of the project (and me) has suffered so I will move on.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum index resetting to 0 at runtime
« Reply #3 on: February 17, 2020, 01:49:03 AM »
Hi,

 yeah, that's what I was suggesting, make an action flexible enough, that does exactly what the call method do only that it talks and access the class directly as opposed to using reflections.

Bye,

 Jean

Dakk

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 21
Re: Enum index resetting to 0 at runtime
« Reply #4 on: February 18, 2020, 03:22:45 PM »
Thanks Jean,
Yes that is probably the right answer- a small set of actions that directly contain my  analytics events instead of trying to reach them via call method.
Passing strings as params is working for me now (just can't use the convenience of enums for some reason), but if I run into issues I will likely change the setup.
Thanks,