Sign In Register

How can we help you today?

Start a new topic
Answered

Sending data to client without making a request

I've got some code that will run after x time then checks if the player is online and if they are I want to send some data to the player in the most efficient manner possible but I can't find a way without messily using cloud code to call a request to call a response and back to Unity.


Is there by any chance any code that I can force a message to be sent to the client and catch it with a callback in Unity?


Thank you


Best Answer

 You could use script messages, this how you send them from Cloud Code:

 

var message = Spark.message();

message.setMessageData({"example":21,"example2":"foo"});

message.setPlayerIds(["id1","id2",Spark.getPlayer().getPlayerId()])

message.send()

 

In unity you'd have a script message listener to intercept these messages. The data will be saved using setMessageData. To set up a listener and retrieve data from it please visit the following doc page:


https://docs.gamesparks.com/api-documentation/message-api/misc/scriptmessage.html


Hope this helps,

Omar


Answer

 You could use script messages, this how you send them from Cloud Code:

 

var message = Spark.message();

message.setMessageData({"example":21,"example2":"foo"});

message.setPlayerIds(["id1","id2",Spark.getPlayer().getPlayerId()])

message.send()

 

In unity you'd have a script message listener to intercept these messages. The data will be saved using setMessageData. To set up a listener and retrieve data from it please visit the following doc page:


https://docs.gamesparks.com/api-documentation/message-api/misc/scriptmessage.html


Hope this helps,

Omar

Worked perfect, thank you

 

Login to post a comment