question

Nathalie Schuster avatar image
Nathalie Schuster asked

Cloudscript function is not defined?

Hi!

I wrote two cloudscript functions and I'm trying to call one function inside the other. But Cloudscript throws an error saying the function is not defined:

ERROR
{
    "FunctionResult": null,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0005269,
    "MemoryConsumedBytes": 5200,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "JavascriptException",
        "Message": "JavascriptException",
        "StackTrace": "ReferenceError: getPlayerDataLastStatsUpdate is not defined\n    at handlers.UpdateStatisticsDecay (15C82-main.js:172:16)\n    at Object.invokeFunction (Script:116:33)"
    }
}

But the function is definitely defined, just a bit further up:

handlers.getPlayerDataLastStatsUpdate = function () {
    var getPlayerInfo = server.GetUserData
        ({
            PlayFabId: currentPlayerId,
            Keys: ["lastStatsUpdate"],
        });
        if (getPlayerInfo.Data.lastStatsUpdate == null) {
            var now = (Date.now()/1000).toString();
            var data = JSON.parse('{"lastStatsUpdate":"'+now+'"}');
            UpdateUserData(data);
            var lastUpdate = now; 
        } else {
            var lastUpdate = getPlayerInfo.Data.lastStatsUpdate.Value;
        }
    return lastUpdate;
}

And I call it like this:

var then = getPlayerDataLastStatsUpdate();

What am I doing wrong to get the error?

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

·
Nathalie Schuster avatar image
Nathalie Schuster answered

Okay, I figured it out. I just had to remove the "handlers" at the beginning.

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.