question

Moayad Babiker avatar image
Moayad Babiker asked

Chaining Cloud Script Execution

Hi, I'm trying to implement item upgrades in my game project, the way I'm going to do it is by defining the upgrade costs and requirements as part of that item's data in the catalog, then whenever the player needs to upgrade an item they would send a cloud Script Execution request to the server passing in the item instance data, from there on the game would need to perform these Server-Side PlayFab API Calls: - Retrieve the upgrade costs and requirements. - Retrieve the player's inventory to check that the player is capable of performing the upgrade. - Deduct the upgrade cost and remove any items required for the upgrade from the player's inventory. And at the end that upgrade API function would need to return a response detailing the result of the operation. I'm unsure how this approach can be implemented within cloud Script, can I simply wait for one API call to complete and then progress with the next one up until I have all the information I need to process the upgrade operation and then return the response all from within the upgrade API function ? Wouldn't that effect my 1 second of CPU allowed for cloud scripts ? Would I have to implement multiple cloud functions and then progress through them from the client ? Or what would be the best way to implement this functionally ?

Thank you.

apisCloudScript
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

·
Sarah Zhang avatar image
Sarah Zhang answered

>> Can I simply wait for one API call to complete and then progress with the next one up until I have all the information I need to process the upgrade operation and then return the response all from within the upgrade API function ?

CloudScript is not atomic, I don’t think we can “simply” execute API calls sequentially. In this case, we need to design some selection logic. We can write some conditional statements in the function to control the progress.

>> Wouldn't that effect my 1 second of CPU allowed for cloud scripts ?

Do you mean the time limit? If you call several API in one function, you should notice both the API calls limit and the time limit. You can navigate to [Game Manager]->[Settings]->[Limits] to check the limits. And you can do the test to confirm the specific time. For example, when customers are essential tier, the max processing time for a Cloud Script function called by the ExecuteCloudScript API is 4.5s and the max number of PlayFab API requests made from a Cloud Script function called by the ExecuteCloudScript API is 15.

>> Would I have to implement multiple cloud functions and then progress through them from the client?

It is not necessary to progress through them from the client. You can write the conditional statements in the CloudScript function. And in one ExecuteCloudScript API call, you can call several PlayFab API whose number is no more than the limits.

>> Or what would be the best way to implement this functionally ?

Using CloudScript is OK. But about how to store upgrade costs and requirement, if they are reusable, It’s better to be stored as Title data. And in my understanding, you can create new items to handle the upgraded items. It will be more easy to implement. Currently, there is not an official best practice about this feature. You can base on the specific situation, find the workaround which is most suitable for you.

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.

Moayad Babiker avatar image Moayad Babiker commented ·

Thank you, I'm terrible with JS so I thought I'd have to wait for the requests to complete, didn't realize they were synchronous, that makes this whole ordeal much easier

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.