How to: Pass booleans through RPC

First of all, yes, I know that RPC’s are outdated but personally I like the legacy system more.

So I found a way to pass booleans through RPC easily (without int or other).

in JS you would do something like this

var myBool : boolean;

function Start(){
var nView = GetComponent.();
nView.RPC(“MyFunc”, RPCMode.AllBuffered, myBool.ToString());
}

@RPC
function MyFunc(b : String){
if(b == true.ToString()){
//true would go here
}
else{
//false here
}
}

And I’m not the best with C# but this is probably how it would go

public Bool myBool;

void Start(){
NetworkView nView = GetComponent(); //not exactly sure how to do local vars in C#
nView.RPC(“MyFunc”, RPCMode.AllBuffered, myBool.ToString());
}

[RPC]
void MyFunc(String b){
if(b == true.ToString()){
//true would go here
}
else{
//false here
}
}

I’d just figured this out and decided to make a thread for it, hopefully it wasn’t just a waist of time.
Maybe it will help a soul or two.

:slight_smile:

The use of the Unity Multiplayer prefix in your topic is confusing, since the prefix is for topics related to the Unet system, not the old legacy system. Also code tags(Insert…->Code) are really handy. [ code=CSharp]blah[ /code] [ code=JavaScript]blah[ /code]

Oh, lol sorry.

How is the prefix related to Unet? I’ve never used Unet before in my life, I’ve always used the legacy system.

Now you made me confused. xD

Help me, please.