question

jeffrbake avatar image
jeffrbake asked

Cloudscript returning success as error

I am testing the basic helloWorld example, and it is always hitting the error return. This is what I am getting:

There was an error =(
{ code: 200,
  status: 'OK',
  data:
   { FunctionName: 'helloWorld',
     Revision: 2,
     FunctionResult: { messageValue: 'Potato' },
     Logs: [ [Object], [Object] ],
     ExecutionTimeSeconds: 0.0001904,
     ProcessorTimeSeconds: 0,
     MemoryConsumedBytes: 2344,
     APIRequestsIssued: 0,
     HttpRequestsIssued: 0 } }

And the code printing that is:

function OnCloudHelloWorld(response: any, error: any) {
    if (error) {
        //console.log(PlayFab.GenerateErrorReport(error));\
        console.log('There was an error =(');
        console.log(error);
        return;
    }
    const result = response.data.FunctionResult;
    console.log(JSON.stringify(result));
    console.log(result['messageValue']); // note how "messageValue" directly corresponds to the JSON values set in Cloud Script
}

The cloud script (I modified it to return potato):

handlers.helloWorld = function (args, context) {
    
    // The pre-defined "currentPlayerId" variable is initialized to the PlayFab ID of the player logged-in on the game client. 
    // Cloud Script handles authenticating the player automatically.
    var message = "Hello " + currentPlayerId + "!";

    // You can use the "log" object to write out debugging statements. It has
    // three functions corresponding to logging level: debug, info, and error. These functions
    // take a message string and an optional object.
    log.info(message);
    var inputValue = null;
    if (args && args.inputValue)
        inputValue = args.inputValue;
    log.debug("helloWorld:", { input: args.inputValue });

    // The value you return from a Cloud Script function is passed back 
    // to the game client in the ExecuteCloudScript API response, along with any log statements
    // and additional diagnostic information, such as any errors returned by API calls or external HTTP
    // requests. They are also included in the optional player_executed_cloudscript PlayStream event 
    // generated by the function execution.
    // (https://api.playfab.com/playstream/docs/PlayStreamEventModels/player/player_executed_cloudscript)
    return { messageValue: 'Potato' };
    //return { messageValue: message };
};

Not sure why it is doing this?

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

·
Hernando avatar image
Hernando answered

I copied your code but could not reproduce this error. It should usually returns an error code when you get an error. Could you post this error code, your TitleID and SDK Version?

Besides, I guess the parameter is missing when you calling the function. Did you pass in the parameter inputValue when the client run this function? If this parameter is null, Cloudscript will report an error in line 13 of function helloWorld.

To solve this error, you can modify the request to this:

var Request = {

FunctionName: "helloWorld",

RevisionSelection: "Live", 

FunctionParameter: {"inputValue": 3} ,

GeneratePlayStreamEvent: true};
10 |1200

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

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.