Regarding RPC variables

Hello,
I have a question regarding RPC variables in a network, because I’m abit confused -
I’m making an online rock-paper-scissors game-

I have 2 gameobjects in the scene, each one controlled by a different client. on both gameobjects there’s the same script with networkview activated.

I have 2 private variables in the script, one for each player decision.
I use an RPC function to update these variables, depending on the tag of the gameobject -
so for example a player controls the gameobject with the tag “player2”, when he makes a decision - the function updates the variables that correspondes to player2.

the problem is - the clients won’t recongnize the variables of the other clients -
so if i’m player1, I can’t access the variable of player2, and vise versa.

Am I missing something? how can I get all clients access to every variable in the script?

What do you mean with RPC variables ? RPC means remote procedure calls, they are just a way to call a function on a remote computer... Are you talking about arguments ? If you call some RPC with an argument, the RPC will be performed with this same argument value on every computer in RPCMode

–

There are a limited number of types of variables that can be sent as arguments to an RPC. Are you trying to send something like a GameObject or Material as an argument? Because that won't work. But that's just a guess. Post the script you're talking about if you want someone to be able to actually give you an answer.

–

I'm giving strings as arguements... here are the relevant pieces of the code: private string dp1; private string dp2; void OnGUI() { if(GUI.Button(new Rect((100,100,,150,75),shoot)) networkView.RPC("SetDecision", RPCMode.AllBuffered, "Shoot"); } [RPC] void SetDecision (string decision) { if(this.tag=="Player1") dp1=decision; if(this.tag=="Player2") dp2=decision; }

–

2 Answers

2

RPC sends the message to same gameobject in others scene. The variables are updated, but not for the “actual” player, but clone he is seeing. Simplest solution would be having gameobject which caches the gameobject of the new spawned-joined player which actually owns the scene. When rpc is received you then actually change that data on real player gameobject.

If i understanded your problem correctly.

The RPC is just sending the string “Shoot”, which contains no information.

Shouldn’t it be sending “Rock”, “Paper” or “Scissors?”

Also, you should use RPCMode.Others and change

if (this.tag=="Player1") 
    dp1=decision; 
if (this.tag=="Player2")
    dp2=decision; 
}

to

if(this.tag=="Player1") 
    dp2=decision; 
if(this.tag=="Player2")
    dp1=decision; 
}

You can set the players’ own decision locally before sending the RPC.

the shoot is just a notation, it could be "rock" for example. I think I didn't explain myself fully or I didn't understand your answer- Each player has his own GUI. If player1 for instance clicks on "rock", I would like to change the variable dp1 to "rock", across all clients. So dp1 stands for the decision of player1, and dp2 stands for the decision of player2. I'd like to be able to change and access these variables across the clients. The problem right now is that If i am player1, and player2 makes a decision, the variable "dp2" remains null for player1 even after the change...

–

ok, i'll give it a try. thanks :)

–