question

Ethan K. G avatar image
Ethan K. G asked

Azure Function Failed with player_statistic_changed rule

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.

Ethan K. G avatar image Ethan K. G commented ·

Just follow the instrction here (https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart#playfab-cloudscript-context-variables-and-server-sdks-), try the HelloWorld sample it works fine in Players / Cloud Script / Run Cloud Script. But it fails with player_statistic_changed rule.

0 Likes 0 ·

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Azure Functions triggered by a Rule uses the PlayerPlayStreamFunctionExecutionContext context model, which is different from the one (FunctionExecutionContext) used in the link you mentioned in question. For instance, here is sample script showing how to handle calls triggered by a Rule:

        [FunctionName("ReturnPlayerProfile")]
        public static async Task<PlayerProfileModel> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] PlayerPlayStreamFunctionExecutionContext req,
            HttpRequest httpRequest,
            ILogger log)
        {
            string body = await httpRequest.ReadAsStringAsync();
            log.LogInformation($"HTTP POST Body: {body}");


            if (req.PlayStreamEventEnvelope != null)
            {
                log.LogInformation($"eventEnvelope: {JsonConvert.SerializeObject(req.PlayStreamEventEnvelope)}");
            }
            else
            {
                log.LogInformation("PlayStreamEventEnvelope was null");
            }


            if (req.PlayerProfile != null)
            {
                log.LogInformation($"playerProfile: {JsonConvert.SerializeObject(req.PlayerProfile)}");
            }
            else
            {
                log.LogInformation("PlayerProfile was null");
            }


            return await Task.FromResult(req.PlayerProfile);
        }
    }


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.

Greg Quinn avatar image Greg Quinn commented ·

This is not clear at all in the context documentation. I spent 30 minutes trying to find out how to get the playerId from a rule, until I stumbled upon this forum post.

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.