question

Vsevolod Metelskyi avatar image
Vsevolod Metelskyi asked

Alternative way of implementing energy restoration logic

I have run out of currencies amount limit but I still need to implement energy and regeneration logic for it. What I thought about is adding energy key to the player title data as a simple json value, writing a CloudScript that would receive players segment as an argument and then loop through all the players from that segment and add 1 to their energy value. And adding a scheduled task to run this script once per hour. Is it going to work with large amount of players (let's say 10 000 players in a segment)? Or am I going to get performance spikes or face API calls limit? How would this approach be different from using native PlayFab regeneration parameters from the Currencies tab?

And I also think that I could have a collision in this case.

For example if I have 10 points of energy and I run a level which subtracts 3 points and the abovementioned script executes at the same time and tries to restore 1 energy point, can I be sure to get 8 energy points after both of these operations are finished executing?

I fear that a situation like this could happen:

1. Energy subtraction script started, it gets current value which is 10.

2. Before subtraction script is completed, restoration script has started executing. It gets current energy value which is 10 as well.

3. If subtraction script will finish sooner, I will have 7 points, but if restoration script will finish sooner, I will have 11.

Is a situation like this could occur with a solution I have described above?

CloudScriptscheduled tasks
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

·
Seth Du avatar image
Seth Du answered

Your solution is feasible using Scheduled Tasks, and you should not interactively selecting players in the Cloud Script which will definitely exceeds the run-time limits. The energy points only depend on the order of recovery/consumption function and these functions should be asynchronous no matter it is called in Scheduled Tasks or directly runs in the client via ExecuteCloudScript API.

I don’t think you should concern too much on this. I am not sure what's the maximum number of the "energy", but there is always this problem when it is reaching the maximum.

Besides, this is a PlayFab built-in supported feature, if you keep using work around solutions, we cannot guarantee there is no potential issue in the future. Our suggestion is if you have specific needs that Essential Tier cannot cover, please contact our sales team via sales@playfab.com and we can customize your limits according to your needs.

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.