question

msaeed avatar image
msaeed asked

how to handle multiple client requests editing the same value at the same time

hello
i'm new here and i would ask about how to handle multiple client requests editing the same value at the same time
for example

 on client 
client send getX() { excuteCloudScript("getX_server") }

on server 

x = 25
handlers.getX_server() {

x= getXfromdb or what ever 
x++ ; 

return ("x" : x } ; 

}



i don't want that 2 clients gets the same value of x while the server getting the request at the same time
i don't know exactly how the server engine work

the second one , is there a database i can use ?


the third one is the server built using node.js ?

the fourth question can i create a loop and a queue to add the clients on the queue and send them the value of x in order


thanks and i hope to get a detailed answer

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

The simple answer is that you should avoid multiple players attempting to write to the same value as much as possible. If you do, either you'll have one client fail on the write and get an error or (worse) both will get a success message, but only the last write will be successful, since it will have overwritten whatever the first write did.

Can you explain specifically what the gameplay feature is you're trying to develop? It's usually best to start with a high-level description of the player experience, so that we can drill down from there and help you design a solution that's most suited to what you're attempting to create.

2 comments
10 |1200

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

msaeed avatar image msaeed commented ·

Im trying to make an auto registeration functionality that if the player hits register the server will generate an incremental user name to register with and after then he can change the username

0 Likes 0 ·
brendan avatar image brendan msaeed commented ·

Sorry, but that's simply not an option. Please see this thread for a more complete discussion, but you would need to use something akin to Redis, if you want to have an incrementing counter across all players:

https://community.playfab.com/questions/956/211248347-Writing-Title-Data-in-Cloud-Script.html

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.