Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by larissa · Oct 06, 2017 at 08:44 AM · CloudScriptdocumentationtasks

Questions on the context parameter

I've recently discovered the existence of the context parameter in cloudscripts and been using it, to make sure certain handlers would only be called from tasks:

handlers.MyHandler= function(args, context)
{
 	// Don't allow this to be triggered by anything but a task
	if (context.hasOwnProperty("triggeredByTask") && context["triggeredByTask"].hasOwnProperty("Name"))
	{
		// Do stuff here ...

	}
}

1.) When using above code, I've noticed the context parameter will not be provided / null for tasks that are run on a player segment? It's been working for the "run cloudscript function once" type of task though.

a) Is this intended? The name "triggeredByTask" certainly suggests, that it would be possible to check it for either type of task.

b) Is there a different way to differentiate between the client calling the handler by itself vs. a task calling the handler for all players in a segment? (Of course there's always the possibility to hand an additional "password-parameter" to the task and check for that, but maybe there's a more elegant way than that?)

2.) Is there any documentation for the context parameter other than the brief mentions in this tutorial (https://api.playfab.com/docs/tutorials/landing-automation/writing-custom-cloud-script), which says

"context is an advanced parameter. In this example, it is null. See this guide(link pending) for more information.This parameter is server-controlled and safe."

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Oct 06, 2017 at 08:46 AM

Yes, the Context is available for PlayStream Action-originating Cloud Script. Here's a tutorial that details this: https://api.playfab.com/docs/tutorials/landing-automation/using-cloud-script-actions-with-playstream. You can also, in the Action definition, specify static data that you pass in as arguments to the Cloud Script, so you could technically also use a secret key system there to provide an argument that couldn't possibly be sent by a client, since they have no access to the PlayStream Action defniitions.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by larissa · Oct 07, 2017 at 10:47 PM

Sorry, I'm not sure if I'm understanding this correctly yet:

The tutorial you linked states:

"Now, the last element of context is triggeredByTask. Unlike the first two, which are set when using Rules and Segment Enter/Exit triggers, triggeredByTask is only applicable when the handler is running as a result of a Task, whether manual or on a timer. It contains only two parameters:

  • Name – The unique name you gave your Task when you created it
  • Id – The unique identifier automatically generated by PlayFab for your Task

For a Task run against a user Segment, you’ll also have the playerProfile, but you won’t have a playStreamEvent."

Doesn't this imply, that the context-property "triggeredByTask" is supposed to be available for tasks that are run against a user segment? However when I tried it, it was null. Specifically the following handler

handlers.MyHandler = function (args, context)
{
	logd("MyHandler context: " + JSON.stringify(context));
	...  

when run by a scheduled task against a segment, would produce the following output:

"MyHandler context:
{
    \"playerProfile\":
    {
        \"PlayerId\":\"5X1BD226109B0211\",
        \"TitleId\":\"6131\",
        ...
    },
    \"playStreamEvent\":null,
    \"triggeredByTask\":null
}"

So even though this was triggered by a task, triggeredByTask is null. Is this intended?

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brendan ♦♦ · Oct 07, 2017 at 10:48 PM 1
Share

Thanks for calling that out. I just tested and reproduced this (the triggeredByTask not being available in the context). I've opened a bug on that to get it fixed asap.

avatar image

Answer by Guillermo Eduardo Sanfiz · Dec 12, 2021 at 12:02 PM

I can not belive that now I can not write code directly in playfab, now I must use Azure and the doc is terrible!! It is not very sure how to get the name arg, the code works calling the function in the navigator, but via the playfab api it fails. Why you (microsoft) made that change???

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SethDu ♦ · Dec 14, 2021 at 08:44 AM 0
Share

Details of context model are listed in PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Docs and you may directly import CS2AFHelperClasses.cs to your project.

Please follow the document -- PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Docs and use the following code to use argument.

FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());

dynamic args = context.FunctionArgument;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    cloud script handlers 1 Answer

    server.DeletePlayer is not a method 1 Answer

    Steam User Info and DLCs 1 Answer

    CloudScript don't have api call documentation & uncomplete CloudScript.d.ts ? 2 Answers

    Can Cloud Code Access the Admin API 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges