- Home /
How do I make variables update on a network script?
Hello,
I've not been able to find this in a search, and the networking tutorial I downloaded from unity was not documented very well compared to their other tutorials. I was a little downtrodden.
I'm trying to send data from a object on server to the client. This object I'm calling the DTH has networkviews attached to both the object and the script. Problem is, everytime the server changes a variable on the DTH, and the client requests that variable, it returns only its original value of "not what I expect". When that same variable is viewed from the server, it changes properly, but when viewed from client, it does not.
Script:
pragma strict
var teststring : String = "not what I expect";
function incstring ( inc : String ) { teststring = inc; }
function checkstring ( requestor : GameObject ) { requestor.SendMessage("updatestring", teststring, SendMessageOptions.DontRequireReceiver); }
So the question is, how do I make it function as I intend?
If this is not possible, what do you suggest as an alternate way to send and recieve updated data.
Try with: requestor.Send$$anonymous$$essage(teststring, Send$$anonymous$$essageOptions.DontRequireReceiver);
This will send the "teststring" value.
Send$$anonymous$$essage is not network method. it will not send anything via network.
Answer by ScroodgeM · Aug 06, 2012 at 09:15 PM
http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html
feedback if need explain
I'm completely confuzzled by the documentation. I tried adding @RPC in front of both methods. No change. I get the feeling I need a decent tutorial to break in down into consumable pieces for me. Sorry that I couldn't get it the first try.
that can't be solved only adding '@RPC' 8)
be sure object that should receive data have NetworkView component
write a receiving method (see link for example) for client
write a sending method (see link for example) for server
networkView.RPC(...);
run server and client
connect them
now, calling the sending method on server should be received by client
Like this?
'#pragma strict
var teststring : String;
function incstring ( inc : String ) { teststring = inc; }
function checkstring ( requestor : GameObject ) { networkView.RPC("checkstringrpc", RPC$$anonymous$$ode.AllBuffered, requestor); }
@RPC function checkstringrpc (requestor : GameObject ) { requestor.Send$$anonymous$$essage("updatestring", teststring, Send$$anonymous$$essageOptions.DontRequireReceiver); }
Sorry to ask but the Unity master server isn't allowing me to connect and test.
i'm not strong in JS, but looks correct...
BUT... Valid RPC parameters are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion.
http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html
you can't send a whole gameobject via network 8) send a link to it as NetworkViewID if this is network object.
realize RPC exactly from example to understand how it works...
Your answer
![](https://koobas.hobune.stream/wayback/20220613075257im_/https://answers.unity.com/themes/thub/images/avi.jpg)