Well actually, my solution only works halfway,
If a client sends a message and I need to send to that exact client a specific message right afterwards, I can use the message.sender ;
But if I need to dispatch a message after some other stuff, I don’t know how to get the presence of the specific user I’m looking for.
I understand this and it works :
dispatcher.broadcastMessage(opCode, JSON.stringify(response),[message.sender]);
The presence is the message.sender, the client sends something, I can immediatly answer to him specifically
But if I need to send him a message for other reasons when the client has not send something before, I don’t understand what to use instead of message.sender.
I tried this :
dispatcher.broadcastMessage(opCodePlayerNotPlaying,JSON.stringify(''),[s.presences[0]])
But it stops the match with the error error":"TypeError: expects a valid set of presences
Long story short, when the two players are joining a match, the first thing they do is to ask the server to receive a playerID, be 1 or 2. On top of that, I can access their userID, username, sessionID and node through the message.sender that I use to set equivalent variables like player01UserIDString, player01Username etc…
I did this in order to try to do the following to send messages :
dispatcher.broadcastMessage(opCodePlayerToStart, JSON.stringify(''),[s.presences{userId:s.player01IDString,sessionId:s.player01SessionID,username:s.player01Username,node:s.player01Node}]);
But it won’t let me compile, saying that Type ‘{ [userId: string]: Presence; }’ is missing the following properties from type ‘Presence’: userId, sessionId, username, node
Tried also to create a player01Presence:nkruntime.Presence variable type in the state so that each client would set it at a specific moment different from match init, but at the match init when state is initialized, I tried to make player01Presence:null and it would not let me saying it can’t be null.
So anyway, I still don’t exactly understand how to send a message to a specific player that is not a previous message.sender and I did not find that specific thing in the github example, all messages send to clients are through message.sender but I need to send messages to specific client that have not started the conversation in the first place.