You can do a last seen in cloud code by putting the following in your AuthenticationResponse:
var lastLogin = Spark.getPlayer().getScriptData("lastLogin"); //Get the last login, probably check that it's not null first to prevent errors.
Spark.setScriptData("lastLogin", lastLogin); //The the scriptData before updating the lastLogin variable
Spark.getPlayer().setScriptData("lastLogin", new Date()); //Update the loginData on the player's profile
Shane
G
Gabriel Sauve
said
almost 8 years ago
If the isOnline function can't be relied upon for all platform, i would prefer to use the "lastSeen" field to decide if a message should or should not be send. However, I can't seem to find a way to do so. And I did thoroughly consulted the SparkPlayer page this time.
G
Gabriel Sauve
said
almost 8 years ago
And the last question on the subject: why does the "online" field stay false when a player is connected from my unity editor when it's made true when connected from the test harness. Even sending correctly 2 custom events does not make the online field go true.
G
Gabriel Sauve
said
almost 8 years ago
Well I just saw that... And I don't understand how i missed it before...
Sounds good. But then my question is how do I get a "myPlayer" object from a playerId?
I have to loop and check which players are online from my array, but i don't see any way to get a player object apart from the Spark.getPlayer() which does not take parameters and return only the active player...
Gabriel Sauve
I would like to send a message to an array of players only if they are online.
If they are not, they will get a complete game state update when login in, and do not need to receive that message later.
How can i read that crucial "online" field in the player collection?
Also, I'm not using challenges.
Thanks for any clues!
https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/spark#loadPlayer
Will load a player object by id.
- Oldest First
- Popular
- Newest First
Sorted by Newest FirstMatteo Grossi
Sorry to resurrect this thread,
is there a way to access any player data (in particular the "online" parameter) from a request in C#?
For example, when i send a GetLeaderboardDataRequest():
foreach (var entry in response.Data)
{
string mytext= "ONLINE " + entry.isonline.ToString();
}
Thanks!
Customer Support
Hi Gabriel,
You can do a last seen in cloud code by putting the following in your AuthenticationResponse:
Shane
Gabriel Sauve
If the isOnline function can't be relied upon for all platform, i would prefer to use the "lastSeen" field to decide if a message should or should not be send. However, I can't seem to find a way to do so. And I did thoroughly consulted the SparkPlayer page this time.
Gabriel Sauve
And the last question on the subject: why does the "online" field stay false when a player is connected from my unity editor when it's made true when connected from the test harness. Even sending correctly 2 custom events does not make the online field go true.
Gabriel Sauve
Well I just saw that... And I don't understand how i missed it before...
Sorry for the inconvenience.
Tech Support
https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/spark#loadPlayer
Will load a player object by id.
Gabriel Sauve
Sounds good. But then my question is how do I get a "myPlayer" object from a playerId?
I have to loop and check which players are online from my array, but i don't see any way to get a player object apart from the Spark.getPlayer() which does not take parameters and return only the active player...
Tech Support
Hi Gabriel
You can check using this:
https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/sparkplayer#isOnline
Sorry, the example is missing (I'll fix that) but it should be
var isOnline = myPlayer.isOnline()
Gabriel
-
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