- Home /
Can RPCS safely send STRINGS?
Can Strings be safely sent in an RPC, or is there more coding required? DEBUGGING INFORMATION INCLUDED..
I send string, int, and float across network to clients via rpc call to all. They only recieve the values for float and int not the string value. I have confirmed this with numerous tests, rewrites and debug routines.
I can post my code but since what I'm doing is very simple I think this should suffice for now. All I am doing is using a RPC call to all and sending a string, float, and int, then reading it back from the client in a debug routine. Its important to note that the string that is sent is used to overwrite a string variable on all clients.
In the picture, server is on the right and client on the left - server typed a message to itself and client. Client reads the float and int, but not the String.
If you choose to answer please try to test this out by writing a simple RPC to send strings, then read back the change to the string variable from the client in a debug routine similar to what I have done. If you do not debug this it is going to be hard to solve.
RPCs are perfectly safe for sending any of the supported data types.
Have you tried simply printing the values to console with Debug.Log()
?
Asafsitner no i havent tried that. I will give it a shot and let you know. Also going to try to send an string inside of an array and see if that works.
Answer by gooncorp · Nov 30, 2013 at 08:57 PM
Sending strings kind of works, if i send a string variable and rewrite a variable on the clients machine it does NOT work. just sending a string however does. Its funny ive been writing all of my own network code and i have never had this problem, im still having a really hard time with this guys...
Answer by gooncorp · Nov 30, 2013 at 07:19 PM
I do not want to use sendmessage. My RPC looks like this:
if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && GUI.GetNameOfFocusedControl () == "Text1" ) {
textFieldOpen = false;
var sendString = (realPlayerName + " : " + stringToEdit) as String;
networkView.RPC ("chat", RPCMode.AllBuffered, "GENERIC TEST STRING = " + " TEST248 " + "SEND STRING = " + sendString, Time.time, Mathf.FloorToInt(Random.value * 20));
if (DEBUG) {
print ("chat rpc called" );}
}
////////////////////
@RPC function chat ( text : String , flVal : float, inVal : int) {
//if (levelNameString.Length > 280) { //levelNameString = ""; //}
debuggingFloat = flVal; debuggingInt = inVal; Debug.Log("RPC FUNCTION CHAT TEXT IS " + text); Debug.Log("RPC FUNCTION CHAT TEXT IS " + text.Length); chatMessages[4] = chatMessages[3]; chatMessages[3] = chatMessages[2]; chatMessages[2] = chatMessages[1]; chatMessages[1] = chatMessages[0]; chatMessages[0] = text;
}
Answer by gooncorp · Nov 30, 2013 at 07:18 PM
@RPC function chat ( text : String , flVal : float, inVal : int) {
//if (levelNameString.Length > 280) {
//levelNameString = "";
//}
debuggingFloat = flVal;
debuggingInt = inVal;
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text);
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text.Length);
chatMessages[4] = chatMessages[3];
chatMessages[3] = chatMessages[2];
chatMessages[2] = chatMessages[1];
chatMessages[1] = chatMessages[0];
chatMessages[0] = text;
}