Hello All,
I just came back to using Playfab and was met with the new Azure Function process for running cloudscripts. I have reviewed all the documentation and done the example projects and am still having some issue writing a simple script. Below I am attempting to simply update the users statistics. A couple things I ran into when trying this out.- I was forced to specify "Playfab.Servermodels." before "StatisticUpdate" due to there also being a "clientmodels.StatisticUpdate". It was giving me an "ambigious code" error. Is this causing issues?
- I can build the current code below fine, however, when I execute the function I get the following:
[2021-12-06T18:06:36.630Z] Executed 'StatUpdate' (Failed, Id=1e17aa13-ac17-492c-a688-e03ef3e04868, Duration=150ms) [2021-12-06T18:06:36.633Z] System.Private.CoreLib: Exception while executing function: StatUpdate. PlayFabCloudScriptPlugin: Object reference not set to an instance of an object.
The cloudscript is written as the following:
using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System.Net.Http; using PlayFab; using PlayFab.CloudScriptModels; using PlayFab.ClientModels; using PlayFab.ServerModels; using System.Collections.Generic; using PlayFab.Plugins.CloudScript; namespace Blockchain.Gaming { public static class StatUpdate { [FunctionName("StatUpdate")] public static async Task<dynamic> MakeApiCall( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log) { var context = await FunctionContext<dynamic>.Create(req); var args = context.FunctionArgument; //The playfab request through the SDK Models that are imported //This is PlayfabAllSDK and PlayfabCloudscriptingPLugin { var request = new PlayFab.ServerModels.UpdatePlayerStatisticsRequest { PlayFabId = context.CurrentPlayerId, Statistics = new List<PlayFab.ServerModels.StatisticUpdate> { new PlayFab.ServerModels.StatisticUpdate { StatisticName = "Level", Value = 2 } } }; var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext); return await serverApi.UpdatePlayerStatisticsAsync(request); } } } }
Is there anyone out there can help me out on this? I have been bashing my head into this code for 3 days trying to grasp Azure Functions for the first time.