question

Timurs Sugajevs avatar image
Timurs Sugajevs asked

FunctionContext CurrentPlayerId

I'm using Azure Functions from unity as in tic-tac-toe sample. I get context with

var context = await FunctionContext.Create(req);

FunctionContext has fields CallerEntityProfile and CurrentPlayerId. Shouldn't CurrentPlayerId be playfabId of caller? Instead it is equal to CallerEntityProfile.Entity.Id, so i need to pass playfabId everytime as function argument. It seems like CurrentPlayerId is wrong(entityId instead of playfabId) or redundant...
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

·
Citrus Yan avatar image
Citrus Yan answered

CallerEntityProfile.Entity.Id and CurrentPlayerId are two different concepts, when you call ExecuteFunction using the player’s EntityToken, which is your case I assume, CallerEntityProfile.Entity.Id would be equal to CurrentPlayerId because the function is called by the player itself; however, if you call ExecuteFunction using the title’s EntityToken, then CallerEntityProfile.Entity.Id would be the title id because it’s called by the title. Moreover, the context FunctionContext used in Tic-Tac-Toe sample is still in beta mode and is subject to change at any time, please see the following code:

https://github.com/PlayFab/CSharpSDK/blob/d61ba9f23bf459e6b766bc3fd6b0945ede9ef553/Plugins/CloudScript/source/PlayFabFunctionContexts.cs#L2

Instead, we provide several context models for developers to use when dealing with CloudScript using Azure Functions, please check out this tutorial:

https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/cloudscript-af-context

8 comments
10 |1200

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

Timurs Sugajevs avatar image Timurs Sugajevs commented ·

This tutorial lack information about how to obtain those context. For example how to get ScheduledTaskFunctionExecutionContext?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Timurs Sugajevs commented ·

Currently there is no official doc on how to obtain each of those contexts, however, the basic idea should be the same. You can take a look at the code by @FranklinChen that gets ScheduledTaskFunctionExecutionContext:

https://github.com/Myfreedom614/PlayFab-Azure-Functions/blob/master/FuncAppV3/CSAFForScheduledTask.cs

Hope that helps, and, you can also find other samples in the same repository.

0 Likes 0 ·
Timurs Sugajevs avatar image Timurs Sugajevs Citrus Yan commented ·

Thanks. It's good example

0 Likes 0 ·
Show more comments
Show more comments
Timurs Sugajevs avatar image Timurs Sugajevs commented ·

More specifically, how do I get the context in a function that I am going to call through scheduled tasks on each player of a segment?

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.