question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

Cloudscript behaves different than normal Javascript?

Hello,

I don't understand why it's happening but Cloudscript behaves different than any other Online JS editor.

- In game code:

This is the code to execute cloudscript:

        int type = 0;
        long totalTake = 408;
        string chance = "93.35";

        ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest()
        {
            FunctionName = "TestFunc",
            FunctionParameter = new 
            {
                Type = type,
                TotalTake = totalTake,
                Chance = chance
            },
            GeneratePlayStreamEvent = true
        };

This is the Cloudscript code:

handlers.TestFunc = function(args, context) {
    if(args == null || args.Type == null || args.TotalTake == null || args.Chance == null) return 0;
    if(args.Type == "" || isNaN(args.Type) || args.TotalTake == "" || isNaN(args.TotalTake) || parseInt(args.TotalTake) <= 0 || args.Chance == "" || isNaN(args.Chance) || parseFloat(args.Chance) < 0) return 1;
    
    return 2;
};

The problem is the Cloudscript returns 1 instead of 2. I don't understand.

- Online JS code:

I wrote a similar code in an online JS editor and the result is 2.

I'm sure, I'm doing something wrong but what is the issue here?

002.jpg (45.4 KiB)
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

·
Citrus Yan avatar image
Citrus Yan answered

Those parameters you passed in the code wrote in the online JS editor are all strings:

“Type”: “0”,

“TotalTake”: “408”,

“Chance”: “93.35”

However, you passed “Type” and “TotalTake” as integers to CloudScript, that’s why the second “if” statement returns true and therefore CloudScript returns “1”.

1 comment
10 |1200

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

Ozan Yilmaz avatar image Ozan Yilmaz commented ·

@Citrus Yan So, when I send parameters to the PlayFab, are they sent by their types as well? If so, is it like number-string types or int-float-string-double etc. types?

Also, I always send float values by converting them to string, so I can control how many digits I can send. Is it normal, or should I just send float values directly?

0 Likes 0 ·

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.