question

sc avatar image
sc asked

Cloudscript 4th argument?

Hi -- in the using Cloudscript tutorial here PlayFabClientAPI.ExecuteCloudScript takes three arguments. But apparently it takes 4, the last argument being an object for custom data of some sort? I'm using the beta -- perhaps this is an update?

Is it possible to update the example to include the 4th argument and how to make use of that?

Also, for beginners like myself, it'd be super awesome if you could include simple examples of how to handle all the callbacks. There's a great example of OnCloudHelloWorld, but there was no example of OnErrorShared -- so I had to dig into the API to discover that the handler needed a PlayFabError signature.

Sorry for being obtuse! But especially for beginner tutorials like this it would be a huge help and I'd probably keep more of my hair.

Thanks very much!

CloudScript
10 |1200

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

brendan avatar image
brendan answered

Actually, it takes 5 arguments:

  • FunctionName - the handler you're calling
  • FunctionParameter - any parameters you want to pass into the call
  • RevisionSelection - the CloudScriptRevisionOption you're using for the call (Latest, Live, etc.)
  • SpecificRevision - the specific revision to run, if the RevisionSelection was Specific
  • GeneratePlayStreamEvent - a boolean to indicate if a PlayStream event should be fired as a result of making the call

Of these, only the FunctionName is required, though if you use Specific for the RevisionSelection, then you do need to provide the SpecificRevision.

Our tools team is working on additional Cloud Script examples, so we should have more that show how to manage things like OnErrorShared soon.

10 |1200

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

sc avatar image
sc answered

I appreciate the quick reply. Yes -- additional CloudScript examples would be super useful for the noobs like me scratching our heads over this stuff. Thank you

10 |1200

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

1807605288 avatar image
1807605288 answered

In all apis for several languages/environments (Unity, Windows, Cocos, Lumberyard, ...) there is a "customData" parameter or option. This is a pass-through parameter. It is passed directly to the callback without being touched. The purpose of this parameter is so that you can track context for your api calls.

Example:

Let's say you are using Characters. You may need to call the same api for two characters at the same time, let's say:

https://api.playfab.com/Documentation/Client/method/UpdateCharacterStatistic

This is a good example because the api-response is empty. If you call this api twice, updating two characters, then in 100-ish ms you'll get two callbacks. You should provide your game-character object in the customData slot. The callback function is provided the request object from the original api call, and a customData object that you provided. With customData, you have enough information to match each callback to each character, and update the correct character object according to the now-successful request object.

ExecuteCloudScript also has a customData field and can be used in the same way. Your client can attach any object there that can be updated appropriately on successful api response. Note, nothing about customData is transmitted to the server, so customData is not useable on the actual CloudScript hosted on our server. Only the api-callback has access to that object.

10 |1200

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

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.