How to securely store temporary data for every player within a real-time match?
T
Tong Zhen Siang
started a topic
over 5 years ago
Hello,
I have read through the cloud code documentation and the tutorial about managing data, but I still have no idea how to actually store a temporary data on the server. I want to let all players who participated in a real-time match to by applied with an integer when the match started. The integer should be able to retrieve from clients and cloud code when the match is still going. Any recommendation on how to achieve this?
Thank you.
Best Answer
T
Tech Support
said
over 5 years ago
I'm not sure what you mean, like this?
var exampleInt = 24
You can just do that on the script and get it from any function, for example if players send packet 66 to the server, the server can send them something back like:
"I want to let all players who participated in a real-time match to by applied with an integer when the match started"
Can you give me more details please,I don't understand why you're trying to achieve.
Who is setting this data? The developer or is this something dynamic?
Cheers,
Omar
T
Tong Zhen Siang
said
over 5 years ago
Like a temporary role, which will be apply to all players in a match randomly. So the data should be set by the server, and not client.
Tech Support
said
over 5 years ago
Hi,
How about something like:
var playersJoined = []; // this is only used at the start to make sure each player is connected
function contains(a, obj) { // this is a simple method that just checks if an element is in an array or not
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
RTSession.onPlayerConnect(function(player){
// first we check to see if the player has already joined the match
if(!contains(player.getPeerId(), playersJoined)){
playersJoined.push(player.getPeerId()); // and add them if not
}
// next we check to see the max (or min) number of players has joined that match
if(playersJoined.length === 2){
//Do something
}
});
This way you can track how many players have joined, when enough have, you can assign them roles/ints?
Hope it helps,
Omar
T
Tong Zhen Siang
said
over 5 years ago
Is it possible to store the int on server? And become available when client make request to the server? Or being use in cloud code?
Tech Support
said
over 5 years ago
Answer
I'm not sure what you mean, like this?
var exampleInt = 24
You can just do that on the script and get it from any function, for example if players send packet 66 to the server, the server can send them something back like:
The server will send a packet of OpCode 6 back to the player that sent the packet 66 to the server. Is this what you're trying to achieve?
Cheers,
Omar
T
Tong Zhen Siang
said
over 5 years ago
I think I have get it, thanks for your helpful replies! One last question, wil the realtime script have an instance on each realtime match, and persist to be same across all players in the match? So I can just store the int as a variable in the realtime script?
Tech Support
said
over 5 years ago
You're welcome, Tong!
Yes, the script is the server version and variables can be given back to each player. You can set intervals in the script to allow the server to execute some logic every once in a while. In the script you can do server authoritative instructions.
Yes, you can store any variable in the real-time script and it will persist.
Tong Zhen Siang
Hello,
I have read through the cloud code documentation and the tutorial about managing data, but I still have no idea how to actually store a temporary data on the server. I want to let all players who participated in a real-time match to by applied with an integer when the match started. The integer should be able to retrieve from clients and cloud code when the match is still going. Any recommendation on how to achieve this?
Thank you.
I'm not sure what you mean, like this?
You can just do that on the script and get it from any function, for example if players send packet 66 to the server, the server can send them something back like:
The server will send a packet of OpCode 6 back to the player that sent the packet 66 to the server. Is this what you're trying to achieve?
Cheers,
Omar
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstTech Support
Hi Tong
"I want to let all players who participated in a real-time match to by applied with an integer when the match started"
Can you give me more details please,I don't understand why you're trying to achieve.
Who is setting this data? The developer or is this something dynamic?
Cheers,
Omar
Tong Zhen Siang
Tech Support
Hi,
How about something like:
This way you can track how many players have joined, when enough have, you can assign them roles/ints?
Hope it helps,
Omar
Tong Zhen Siang
Tech Support
I'm not sure what you mean, like this?
You can just do that on the script and get it from any function, for example if players send packet 66 to the server, the server can send them something back like:
The server will send a packet of OpCode 6 back to the player that sent the packet 66 to the server. Is this what you're trying to achieve?
Cheers,
Omar
Tong Zhen Siang
Tech Support
You're welcome, Tong!
Yes, the script is the server version and variables can be given back to each player. You can set intervals in the script to allow the server to execute some logic every once in a while. In the script you can do server authoritative instructions.
Yes, you can store any variable in the real-time script and it will persist.
Cheers,
Omar
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics