I am creating a card game, and I would like to send a decklist, contained in an int to the other players through an RPC. As I understand, you cannot pass an int parameter into RPC, so I am looking for a function to “encode”/“decode” my int into a byte or string to pass the data through, or otherwise other possible solutions for such a problem. Did a bit of searching, and while the “basics” were there, there wasn’t anything conclusive.
Thanks!
Turn it into a string. Shortest way is to convert your 1-52 into ASCII codes (each number takes 1 byte,) but probably just and good as easier to debug is to use plaintext – each number would use two bytes, 104 total. I think each message is at least a K, so same bandwidth either way, just a tiny but more CPU cycles for strings:
// create the string:
string M = "";
// Assume C *has the number of the shuffled card*
for(int i=0;i<52;i++) {
string crd = “”+C*;*
if(C*<10) crd = “0”+crd; // leading 0 so each uses exactly 2 chars*
M += crd;
}
// ex: unshuffled deck give M = “0102030405…505152”
// Send M
// Decode the string:
// Recieve M
Debug.Log("got deck: " + M);
for(int i=0; i<52; i++) {
string crd = M.Substring(i*2, 2); // pulls out “01” “02” …
C = Convert.ToInt32(crd);
}