Network RPCs Explanation

I’m a little irritated… i tryed all example, all of all, but nothing!

i have an object called DirectGUI, in this object i have a script called ScriptGUI, ok, in this script i have a variable called Name, that i can edit with a textbox.

now i have another object called FPSPlayer, This is not in the game, will be only created at run-time, in this object i have a script called Player, end i have a variable called Nick, i want that in function Start, the var Nick, will be the same of the var Name in the other script, in the other object, but i got lot of errors… i tryed this at last:

function Start() {
object=GameObject.Find(“DirectGUI”);
script = object.GetComponent(“ScriptGui”);
nick = script.Name;
}

but i got “Name is not a member of Unity.Component”…

and i tryed also other example but didn’t work… why? :(:frowning:

i want simply acces a variable in another script in another object… i repeat, the object FPSPlayer, isnt in the game, is only a prefab that will be created in the game… and after created i want that Nick will be the same of Name…

Hi Xarro,

You should have the quotes around ScriptGui since this is a type not a string.

Try…
script = object.GetComponent(ScriptGui);

I got, “unknow identifier ScriptGUI”… but the script exists…

Perhaps try (scriptGui), not (ScriptGui).

The project pane sometimes displays names as upper case, when they are in fact lower case.

I’m only working in C#.
I need to cast it from Component to the Script class name.

public ScriptGui script;

script = (ScriptGui)object.GetComponent(“ScriptGui”);

Did you declare script to be a particular type or were you letting js do it. The type returned from your line is Component and it needs to be ScriptGui so you can access the variables.

On a different subject. Variable names should start with a lower case character. That has nothing to do with your error, its just a standard way of coding.
Class and function names start with capitals.

i dont know, and the name is correct… in some example i saw

var scr : ScriptGUI;

function Start()
…
}

but if i try this i got ScriptGUI is not a valid type or something… :frowning:

From your original post:

This error is correct. It’s lowercase .name

no my variable is “Name”… with the N not “n”… i tryed to change the variable to “myname” all lowercase… but dont change nothing :(:frowning: why??

Try this:

var scr : ScriptGui;

You made the UI caps.
Its supposed to be ScriptGui I think, if thats your script name, with ui in lower case.

This is what works for me:

First re-name your variable in the other script, it’s going to be confusing to call it ‘Name’, I’ll call it ‘banana’ for now. Make sure it is not declared as a private var.

So in DirectGUI’s Script put:

var banana : string = "";

In the other object’s script, put:

private var DirectGUI : ScriptGUI;

function Start() {

	DirectGUI = FindObjectOfType(ScriptGUI);

}

… now, from the other object’s script, you access your variable ‘banana’ in DirectGUI’s script like this:

DirectGUI.banana = “Yo!”;

Simples.

Hope this helps.

now it work… i think it was the var “Name” :slight_smile:

EDIT: Hey thx your example will help me, but i resolved before read :slight_smile: simply this:

var guiobj = GameObject.Find(“DirectGUI”);
nick = guiobj.GetComponent(“ScriptGui”).myname;

great! pleased you got it sorted.

Don’t get irritated, get even.

i dont want open another thread, i will change the name of the topic, but i cant figure how the RPC of the network work when a new player join… it work well… but i dont know…how xD

for example…

join player 1;
join player 2;

now join the player3, how he know the number of player already in the game and create this? with the buffer? and if i want clear the buffers of the RPCs, when a new player join, he will not see other player? ???
if someone will give me a good explanation… thanks, Mauro

No one?

Check out the documentation part for networking, especially Network.Instantiate and the RPC Modes (buffered calls generally must be called by the server to be buffered for other clients)

Don’t expect people to give you answers on that unprecise questions.
If you have a specific problem with your implementation, please post detailed information and code for it.
But if you have not even an idea on how to start, check the documentation and Network Example project in the support section of the website to get basic ideas on how anything works at all.

sorry…i read and now i know…:slight_smile: and im creating a multiplayer fps…and all is working…and in the same city the sync its amazing