This shows you the differences between two versions of the page.
|
pjv:laboratoare:2025:a04 [2025/11/26 13:22] andrei.lapusteanu |
pjv:laboratoare:2025:a04 [2025/11/26 17:53] (current) andrei.lapusteanu Fixed cloudscript incorrect code |
||
|---|---|---|---|
| Line 189: | Line 189: | ||
| <code javascript> | <code javascript> | ||
| - | handlers.IncrementCounter = function(args, context) { | + | handlers.incrementCounter = function(args, context) { |
| var res = server.GetUserReadOnlyData({ | var res = server.GetUserReadOnlyData({ | ||
| PlayFabId: currentPlayerId, | PlayFabId: currentPlayerId, | ||
| Keys: ["Counter"] | Keys: ["Counter"] | ||
| }); | }); | ||
| - | | + | |
| var count = 0; | var count = 0; | ||
| if (res.Data["Counter"] !== undefined) { | if (res.Data["Counter"] !== undefined) { | ||
| Line 200: | Line 200: | ||
| } | } | ||
| count++; | count++; | ||
| - | | + | |
| server.UpdateUserReadOnlyData({ | server.UpdateUserReadOnlyData({ | ||
| PlayFabId: currentPlayerId, | PlayFabId: currentPlayerId, | ||
| Data: { "Counter": count } | Data: { "Counter": count } | ||
| }); | }); | ||
| - | | + | |
| return count; | return count; | ||
| }; | }; | ||
| Line 213: | Line 213: | ||
| <code csharp> | <code csharp> | ||
| - | void CallCloudScript() | + | private void CallCloudScript() |
| { | { | ||
| - | PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest | + | var request = new ExecuteCloudScriptRequest |
| { | { | ||
| - | FunctionName = "IncrementCounter" | + | FunctionName = "incrementCounter", |
| + | GeneratePlayStreamEvent = true | ||
| + | }; | ||
| + | PlayFabClientAPI.ExecuteCloudScript(request, | ||
| + | result => | ||
| + | { | ||
| + | var counterValue = Convert.ToInt32(result.FunctionResult); | ||
| + | Debug.Log($"Returned counter value: {counterValue}"); | ||
| }, | }, | ||
| - | result => Debug.Log($"Counter: {result.FunctionResult}"), | + | error => |
| - | error => Debug.LogError(error.GenerateErrorReport()) | + | { |
| - | ); | + | Debug.LogError($"Cloud Script error: {error.GenerateErrorReport()}"); |
| + | }); | ||
| } | } | ||
| </code> | </code> | ||