Sign In Register

How can we help you today?

Start a new topic
Answered

Spark.getPlayerIds always returns an empty array

 Any idea why?


Best Answer

from documentation of Spark.getPlayerIds

This can be accessed in both Global Message Scripts and User Message Scripts

So I Think it is way it returns empty array in other context.


you can't use it to send message to all players in database.You can use it in cloud code messages scripts to easly access target players of given message.


In what context are you trying to use it?


It is only valid when you are using it for Global Messages, it is not valid in any other context.

 I'm trying to use it in that context. How do I then send a message to all players?

Spark.sendMessage({"a":"b"}, Spark.?);

 Since send message needs a SparkPlayer object, I can use Spark.loadPlayer(playerId), but I need to get all the player ids first. Any thoughts?

I would also like to know this. Thanks for your help!

Answer

from documentation of Spark.getPlayerIds

This can be accessed in both Global Message Scripts and User Message Scripts

So I Think it is way it returns empty array in other context.


you can't use it to send message to all players in database.You can use it in cloud code messages scripts to easly access target players of given message.

The best way to go about messaging all players at the moment is to maintain a separate runtime collection of playerId's and query that. You can do this multiple ways, create an event that adds the user's id to the Database, add it in Registration Request or add it in Authentication Request.


Shane

Login to post a comment