I have seen quite a bit of examples and documentation until now regarding rpc and client server however, there's a very stupid and very obscure subject on which I hope those good amongst you can shed some light: requesting a server variable from a client, and updating said value... when the scripts are in different gameobjects.
I have seen quite some examples of RPC calls when the script calls an rpc function on that same script on the server or .others, but what about calling an rpc function somewhere else, asking for a variable value, or trying to set up a variable there?
My attempts at making a STATIC rpc function, or even a very stupid "return server variable" rpc function have failed miserably, especially since RPC returns always VOID.
Please help, thanks.
This is basically the code that I need to use, but that doesn't update my needed variable, when run client-side.
Ok I've understood what's going on. The code is correct, but there's a timing problem. In particular, here
networkView.RPC will run and will immediately return focus to the OnNetworkLoadedLevel, without waiting for completion. variable WILL actually be correctly updated... but long after the calling routine has completed. How do I fix this? Is there a way to put the script to 'sleep' until networkView.RPC completes the call, or I'm just using the wrong approach? It feels like the second option, actually. As a matter of fact, I'd rather have the connection time out rather than the script going forward without the expected variable value.
answered Aug 03 '11 at 03:41 PM