question

forplayers.co avatar image
forplayers.co asked

[CloudScript] undefined parameters if ExecuteCloudScript called on Android

Hello,

CloudScript:

var itemInstanceId_t = args.itemInstanceId;
    var colorName_t = args.colorName;
  
    log.info("ItemInstanceId: " + itemInstanceId_t);
    log.info("ColorName: " + colorName_t);
    
    var dataPayload_t = {};
    dataPayload_t["color_name"] = colorName_t;
    
    var itemCustomData = server.UpdateUserInventoryItemCustomData(
    {
        PlayFabId : currentPlayerId,
        ItemInstanceId : itemInstanceId_t,
        Data : dataPayload_t
    });


    return { messageValue: "Custom data updated!" };

Unity C#:

object dataToSend_t = new
        {
            colorName = colorName_p,
            itemInstanceId = inventoryItemInstanceId_p
        };
        Debug.Log("[PlayfabApplyCustomization] sending " + colorName_p + "  " + inventoryItemInstanceId_p);

        PlayFabClientAPI.ExecuteCloudScript(
            new ExecuteCloudScriptRequest()
            {
                FunctionName = "SetVehicleCustomData",
                FunctionParameter = dataToSend_t
                ,
                GeneratePlayStreamEvent = true
            },
            (success) => { },
            (error) => { });

When I execute this script under Windows, the parameters are well received on playfab side and the CloudScript is successfully executed, but when I execute it under Android, an error tell me that colorName and itemInstanceId are undefined.

I'm using Unity 2018.2.12f1.

I changed the request type but it still occurs.

Thanks per advance for any help,

Alexandre

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

We have tested your code and it seems fine on our test demo. Playstream shows success messages when on both Unity client and android device.

Undefined error messages can be caused by that relevant object definition is commented automatically because of your Unity settings.

When implementing games on multiple platforms, we usually make use of a unity feature named Platform dependent compilation. Detailed information about this feature is provided here.

Please check your script source code if there is similar following usage. Under normal circumstance, there will be only one platform activated.

#if UNITY_STANDALONE
	// do things when targeting to PC
#endif

#if UNITY_ANDROID
	// do things when targeting to Android
#endif
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

forplayers.co avatar image forplayers.co commented ·

Thanks for the reply.

Did you tested on a real device? I'm sure I don't have platform dependent compilation parts. I use the exact same code as above.

If that was a platform dependent compilation problem, then it should not work inside the editor when it is configured for Android, whereas it works.

Debug.Log("[PlayfabApplyCustomization] sending " + colorName_p + "  " + inventoryItemInstanceId_p);

When this line is called on an Android device, ADB logs the right values, whereas on playfab side it says it's undefined

0 Likes 0 ·
forplayers.co avatar image forplayers.co forplayers.co commented ·

I'm very sorry, it was my fault! In fact there was an obfuscator that was changing the variables name.

Thanks again for the support!

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.