Sign In Register

How can we help you today?

Start a new topic
Answered

Getting all players available in player table

Hi,


does anybody know how to get all players id


Spark.getPlayerIds() is empty with length = 0.


also I have tried using find method to get an array of all players with key-value query:

Spark.find("player", {"gameId": 210593}))


but still empty :(


Thank in advance.


Best Answer
Hey Andrii,

There isnt really anyway to access the player-data directly in the way you want to. This is to protect system-critical data, like the player-data that could mess the whole db up if someone added some bad data.

There are a few work-arounds though.
You could use the AuthenicationRequest cloud-code event to add each player to a collection called 'playersOnline' and remove the player when they disconnect.
Or, using the same cloud-code events, you could add all online player to one team, and remove them when they disconnect.

Hope that helps,
-Sean

 


7 people have this question
1 Comment

Answer
Hey Andrii,

There isnt really anyway to access the player-data directly in the way you want to. This is to protect system-critical data, like the player-data that could mess the whole db up if someone added some bad data.

There are a few work-arounds though.
You could use the AuthenicationRequest cloud-code event to add each player to a collection called 'playersOnline' and remove the player when they disconnect.
Or, using the same cloud-code events, you could add all online player to one team, and remove them when they disconnect.

Hope that helps,
-Sean