gameObject.GetComponent freezing script..

I have a MenuScript.js in my Standard Assets/Scripts folder, I am trying to access the variable “menuPage” from my network handler CSharp script which is compiled later.

The compiler engine appears to find the scope of the script/variable I am trying to reference but every time I use gameObject.GetComponent to reference that variable, my CSharp script stops processing.

Here is the code I am using in my CSharp script. If you need any other info/screenshots just ask and I can post it for you.

Thanks in advance to anyone willing to help me with this issue.

	if (cmd[1] == "001")
	{
		print("Logged in, open character select screen!\n");
		MenuScript other;
		other = gameObject.GetComponent("MenuScript") as MenuScript; // Right here the script freezes!
		other.menuPage = "charlist";
		print("Done opening character select screen.\n");
	}

If the MenuScript is part of this object, can you try:

MenuScript other = (MenuScript)GetComponent<MenuScript>();

If it is not part of this object, try:

MenuScript other = GameObject.FindObjectOfType(typeof(MenuScript));

It is part of the same game object (in this case an empty game object I called MenuHandler), it still freezes when I call:

MenuScript other = (MenuScript)GetComponent<MenuScript>();

And to clarify when I say it freezes the script, the CSharp script will no longer receive or parse data being sent over the sockets from the server as soon as I try and use GetComponent … and it never issues the second ’ print() ’ saying done opening character select screen… very strange …

This particular object “freezes” or the whole application freezes?

Have you looked in the editor to ensure it is assigning the MenuScript properly? Also, there must be some other factors in play, what else is happening around this time?

It is only a main menu with a logo GUITexture, a MenuHandler Empty-Object and the Main Camera.

The MenuHandler object has MainMenu.js which draws the GUI TextFields and 2 buttons (login and quit).

The MenuHandler object also has MySockets.cs, which connects to a multiplayer server.

When you enter username/password it sends the user and password, the server then replies whether or not you supplied a correct username and password. Once the correct username and password is supplied, the server then sends a list of characters stored in the database. At this point I want to tell the script to change the variable menuPage from ‘login’ to ‘charlist’. As soon as I use GetComponent, nothing else in the MySockets.cs script happens, not even the very next line; print(“Done opening character select screen.\n”);

If GetComponent() fails, it returns a null, which should not be a problem. Is your script MenuScript compiling properly? If you want to zip it up, you can mail me what you have, but am going up into the mountains for camping (should be plenty of snow) for a while.

You string menuPage might be better as an enumeration, just because they are a little easier to use.

Yeah the MenuScript.js compiles properly, when I .RAR up the project folder it comes out to 85 mb … Should I just pack up the script files or what do you suggest? I am uploading the 85mb .RAR I have now, and I created a temporary user/pass for you in the database ( JRavey / temp123 ). I have nothing to hide at this point, it’s at the beginning of the project. How would you recommend using menuPage as a enumeration? Would that alleviate my troubles trying to share JS variables? Thank you so much for your help and I hope you have a awesome weekend in the mountains!

Here is the link to my project dev folder (I keep it in c:\edgedev) – again your username / password is JRavey / temp123

Note: when you click connect after entering your user/pass it will appear like nothing happened (look at the debug console to see that you actually logged in, when you see the server sending the login headers (:centauri 001 Jravey…)

If you make the script work properly the login boxes should dissapear (because menuPage changed away from “login”)

I got it working by going the other way around and making the variable in C# then calling it from JS … thanks for the help anyway! Hope you had an awesome weekend in the mountains.