Hola people! Im pretty fustrated because i cant send an array in my rpc. After some math and some adjustments to an array that sorts the highest fragger and such, the server sends via RPC to all clients the array that contains all the necesary info so everyone else know the overall score in the game. networkView.RPC("despliegaDatos",RPCMode.All,totalData); But in keep getting errors about my parameter... but then, in unity script reference i see: RPC (name : string, target : NetworkPlayer, params args : object[]) <---- object[]!!! why i cant send arrays?!! the game nature wont allow me to send several parameters, it has to be a whole bunch, and the size of the will decrement or increment depending on the players inside the room. How can i send an array via RPC???
Turn it into a string and parse it in the RPC function. Or, do something like this: Code (csharp): networkView.RPC("SetDataCount", RPCMode.All, data.length); for (d=0;d<data.length;d++) { networkView.RPC("SetDataItem", RPCMode.All, d, data[d]); } Each SetDataItem RPC changes one item in the array at the index of (first parameter).
starmanta, thanks for that useful advice... i did an rpc to all clients with a huge string with all the info of my array. the only problem now... is spliting it into the original form lol. im pasting the entire string on each client screen. i need to give it format. im currently using a: Code (csharp): arreglo = estring.Split("-"); substitute... any ideas, so far i haven't found it..
That's pretty much the way you do it. Use a delim char that you don't use in the parts and just split based on that. There are possibly more efficient ways dealing with changing the string to binary and sending that across, but I find for most things, sending strings along is generally find and good to start out that way.
for 1-dimensional arrays a delimited string is the best option. sending multiple RPCs could get a little heavy on network traffic, particularly if it's a large array. for multi-dimensional arrays i would advise converting the data into XML and sending that as a string via an RPC.