- Home /
Unity Javascript debug error stating BCE0044: expecting :, found ';'. Any help?
I'm sure, for what I want to accomplish, there are many problems with this script, but the one that's stopping me in my tracks right now is Unity saying there should be a colon and I've absolutely no idea how that makes any sense, and I've looked up quite a bit on the topic online to no avail. Any help would be massively appreciated, and I'll give any extra information if it's necessary. Thank you very much in advance if you can suggest anything or help at all. So, here's my script (with // annotations describing things)-
#pragma strict
//Main character collides with village, and 'enters' it.
var visitedvillage = false;//variable stating that the character has (or has not, for false) visited the village recently. Here to make sure that after exiting the menu, the collision will not trigger again (since the character will still be colliding with the village object) until the variable is removed (by exiting contact with the object, or after a set time has passed, presumably). As of right now, you will only be able to visit the villageo once per game start, but that's not really a problem for the time being.
var mediumvillagescreentoggle = false;//variable simply stating that the village menu is not currently open (false).
function OnControllerColliderHit (hit : ControllerColliderHit) {
if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
if (visitedvillage == "false"){//when the main character collides, it checks if they have already visited the village recently, if they have (true) it will not fire and nothing happens, preventing an endless loop of opening the menu each time you close it once you collide with the village.
mediumvillagescreentoggle = "true";//toggles the village menu
if (mediumvillagescreentoggle == "true") {//not sure where else to put this besides here, though this basically jsut turns on the menus/buttons when true.
OnGUI(); {
GUI.Box(Rect(110,10,400,300),"Medium Village");//should open a box, right? but unity says BCE0044: expecting:, found ';'. I have no idea how this makes sense.. any help is greatly appreciated.
}
OnGUI(); {//added a second independent OnGUI in hopes it would help. It doesn't seem to have done anything, or hurt anything, so I haven't removed it.
if (GUI.Button=(Rect(120,40,180,60), "Leave Village")) {//should simply open a button that, when clicked, turns off the village menu.
mediumvillagescreentoggle = "false";
}
}
visitedvillage = "true";
}
}
}
}
}
Answer by Bunny83 · Oct 22, 2013 at 06:06 AM
You can't define OnGUI inside other functions. OnGUI is a callback function. It needs to be a member function of your script. What you've done here makes no sense at all ;)
Next thing is you can't assign a string "true" to a boolean. UnityScript is not (web)javascript, it's way different.
function OnControllerColliderHit (hit : ControllerColliderHit) {
if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
if (visitedvillage == false){
mediumvillagescreentoggle = true;
}
}
}
function OnGUI() {
if (mediumvillagescreentoggle) {
GUI.Box(Rect(110,10,400,300),"Medium Village");
if (GUI.Button=(Rect(120,40,180,60), "Leave Village")) {
mediumvillagescreentoggle = false;
}
}
}
Answer by OrbitSoft · Oct 22, 2013 at 06:21 AM
On line 12/19/22 you are setting BOOLEAN variables to STRING, i think this is not possible. remove the "".
Next is that you are calling OnGUI in there, i suggest you to do the following:
#pragma strict
//Main character collides with village, and 'enters' it.
var visitedvillage = false;//variable stating that the character has (or has not, for false) visited the village recently. Here to make sure that after exiting the menu, the collision will not trigger again (since the character will still be colliding with the village object) until the variable is removed (by exiting contact with the object, or after a set time has passed, presumably). As of right now, you will only be able to visit the villageo once per game start, but that's not really a problem for the time being.
var mediumvillagescreentoggle = false;//variable simply stating that the village menu is not currently open (false).
function OnControllerColliderHit (hit : ControllerColliderHit) {
if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
if (visitedvillage == false){//when the main character collides, it checks if they have already visited the village recently, if they have (true) it will not fire and nothing happens, preventing an endless loop of opening the menu each time you close it once you collide with the village.
mediumvillagescreentoggle = true;//toggles the village menu
visitedvillage = true;
}
}
}
function OnGUI() {
if (mediumvillagescreentoggle == true) {
GUI.Box(Rect(110,10,400,300),"Medium Village");
}
}
I did not test the code but i hope it works.
Thank you both greatly, I haven't had the chance to work on fixing it yet (just finished my midterm for a class tonight, I was actually procrastinating when working with unity), but I'll let you know what happens. Again, thank you both very much for the help, I was completely unaware of virtually everything you said until now. I'll try to work on it tomorrow. (:
Yep, using parts of both suggestions I got it working wonderfully; thank you both again very much, I appreciate the help.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
How Do I Make A Health Bar 6 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
why when i try to add my script to the "player" it says can not can not add script 1 Answer