Search Unity

RPC, are you my enemy???

Discussion in 'Scripting' started by Smireles, Jul 31, 2008.

  1. Smireles

    Smireles

    Joined:
    Jun 20, 2008
    Posts:
    38
    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???
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Turn it into a string and parse it in the RPC function.

    Or, do something like this:
    Code (csharp):
    1.  
    2. networkView.RPC("SetDataCount", RPCMode.All, data.length);
    3. for (d=0;d<data.length;d++) {
    4. networkView.RPC("SetDataItem", RPCMode.All, d, data[d]);
    5. }
    6.  
    Each SetDataItem RPC changes one item in the array at the index of (first parameter).
     
  3. Smireles

    Smireles

    Joined:
    Jun 20, 2008
    Posts:
    38
    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):
    1. arreglo = estring.Split("-");
    substitute... any ideas, so far i haven't found it..
     
  4. Timmer

    Timmer

    Joined:
    Jul 28, 2008
    Posts:
    330
    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.
     
  5. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    167
    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.