question

admin avatar image
admin asked

Calculating game results in CloudScript

Hello,

I'm working on a turn-based game, using PlayFab and Photon. At the end of each game, rank points are awarded to both players, which is done in CloudScript. Because of how it is calculated, the calculation can only happen once for each game, rather than each player individually.

Currently I have both players execute a CloudScript function, and the first player caches the result, while the second simple reads the cached result. However, there is some timing issues with this approach (both requests can happen at the same time, so both run the calculation).

I think a better approach is to have only the Photon master client send the request to calculate the game results, then send the results to the other player through Photon.

Is this the correct approach, or is there a better way to do it?

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.

1 Answer

·
brendan avatar image
brendan answered

So it sounds like in your game, both players can take actions at the same time - is that correct? For games where players must take turns, it's very straightforward, since you can save a "whose turn is it" value which gets updated in CloudScript when that player takes a turn (and you can use a timer check when the other player signs in, to see if you want to have that player forfeit due to elapsed time). If both the players can take actions at the same time, I would recommend using Photon Realtime, as you are thinking. That way, you can create a room where you can manage the realtime interactions, and so make sure that only one player is writing out the data.

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.