question

joe.lavoine@gmail.com avatar image
joe.lavoine@gmail.com asked

CloudScript best practices?

Hello,

I've recently discovered PlayFab and am super excited by all the features available! In regards to using CloudScripts to run game logic, I had a question about best/ideal practices.

Let's say the player wants to upgrade their weapon. I imagine I would have a few CloudScript functions: initiateUpgrade, canUpgrade, payForUpgrade, etc. When the user clicks the "Upgrade" button, I run initiateUpgrade, which deducts player items and currencies, changes the read-only data to account for the new weapon, etc. I could then return the new state of the data from the CloudScript and use it to drive UI on the client.

My questions:

1) When running logic like this, is it best to wait for the CloudScript to return and parse the return values in order to drive UI on the client? My concern is that if the player is buying or upgrading a lot of things, this introduces micro bursts of 1-2 seconds (however long the cloud call takes) after each action.

2) Is it better instead to fire off the CloudScript call, then reflect changes in the UI right away, and finally after the CloudScript returns, update the UI if the data differs. This seems most responsive, but then I would be duplicating some logic between the CloudScript and client.

Similarly, if I want to highlight buttons or show potential costs of an item in the UI, I would still need to do some logic on the client to see if the user could afford an upgrade, etc. The same logic I've written in the CloudScripts.

The best solution I've come up with so far would be to store even more read-only data for the player. For example, the item would have a kvp "canUpgrade : true" that is set in a CloudScript, and the UI would simply be driven by that. I wonder if this is taking the idea of a "thin client" too far? It also doesn't answer whether or not I should be waiting for the CloudScripts to return, or still operating on local data and updating it if it gets out of sync.

Any feedback is appreciated =)

- Joe

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

So the idea is that you're creating an "upgrade" system for items in the player inventory, where if the player chooses to upgrade, it consumes both items and (potentially) virtual currencies? Granted, we have purchase systems now, and we're planning on providing an alchemy/crafting system later on (items and/or VCs go in, different items and/or VCs come out, according to recipes you set up in the game configuration), but taking items/VCs in order to set Custom Data on an item would clearly not fit into either of those models cleanly.

Since each Cloud Script call would take some time, given the ping time from the user to the service backend (as well as the potential for dropped packets if their connection is bad), I would go with doing the upgrades locally and then syncing it with the backend. You'll want to sync before they use the items, of course, but I'm thinking you'd want to when they exit the interface, when the number of items being upgraded "caps" the Cloud Script call (more on that in a sec), or when they next come back into the game. For "capping" the Cloud Script call, I'm referring to keeping track of how many API calls you'll need to make in Cloud Script to account for the exchange. So, one call to get the catalog, another to decrement a count from an item, still another to subtract the VC, and then one more to grant the items. Your savings on API calls would then be on all but the decrement of the count from the item instances, though you'll definitely want to check all the balances before doing the decrement. Also, you'll want to have try/catch statements throughout, so that you can reverse the process if this fails anywhere.

Alternately, if you have animations for the upgrades, that might introduce enough time between calls that you could just do each upgrade when they ask for it.  :)

In terms of protecting yourself against hacked clients, it is possible to be so extreme that it slows the gameplay overall (as well as blocks it when you don't have a connection). The key thing to decide is how much you need to protect the experience, and whether requiring a connection is valid for your user base. In many cases, having the core game require that connection while you have an alternate mode of play for when the player is offline is an option.

10 |1200

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

joe.lavoine@gmail.com avatar image
joe.lavoine@gmail.com answered

Hi Brendan,

Thanks for the response, some interesting things to think about. I had kind of "given in" to the idea of the game requiring an internet connection to play. I think I still need to do some work around playing with CloudScript, seeing how long calls typically take, and how many API calls to actually make the changes.

From everything I've seen so far, PlayFab is a really great product, and you do an amazing job at answering forums posts. Looking forward to working with the SDK!

- Joe

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

Thanks, Joe! We're looking forward to seeing what you make, using PlayFab. :)

The Cloud Script calls should come back quite quickly - you'll get all the info on processing time in the response, so you can track that as you experiment with different handlers.

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.