- Home /
BCE0004: Ambiguous reference 'Label'
Hi there i have a possible stupid question but hang in there. When i went into playmode with this script it worked just fine but when i went to build it it came up with this error:
Assets/Assets/scripts/Character menus/character skills.js(221,34): BCE0004: Ambiguous reference 'Label': UnityEngine.GUI.Label(UnityEngine.Rect, UnityEngine.GUIContent), UnityEngine.GUI.Label(UnityEngine.Rect, UnityEngine.Texture), UnityEngine.GUI.Label(UnityEngine.Rect, String).
here is a copy of the script:
///////////////////
var myskin : GUISkin;
var level ;
var playerhealth ;
var maxfatigue ;
var magic ;
var strength ;
var accuracy ;
var ranged ;
var Totalattack ;
var defensiveability ;
var totaldefense ;
var unarmedtactics ;
var unarmed ;
var unarmedability ;
var intelligence ;
var woodsmanship ;
var swimming ;
var horsemanship ;
var leatherworking ;
var woodworking ;
var cooking ;
//
var skillsxp;
var maxunarmedtacticsxp;
var maxunarmedabilityxp;
var maxunarmedxp;
var maxtotaldefensexp;
var maxlevelxp ;
var levelxp ;
var playerhealthxp ;
var maxfatiguexp ;
var fatiguexp ;
var magicxp ;
var maxmagicxp ;
var strengthxp ;
var accuracyxp ;
var maxaccuracyxp ;
var rangedxp ;
var maxrangedxp ;
var Totalattackxp ;
var defensiveabilityxp ;
var totaldefensexp ;
var unarmedtacticsxp ;
var unarmedxp ;
var unarmedabilityxp ;
var intelligencexp ;
var woodsmanshipxp ;
var swimmingxp ;
var horsemanshipxp ;
var leatherworkingxp ;
var woodworkingxp ;
var cookingxp ;
var Totalevelsxp ;
var accuracyxpbar;
var maxtotalattackxp;
var maxplayerhealthxp;
private var characterstats;
/////////////////////////////////////////////
function Update(){
if(Input.GetKeyDown("Backslash")){
if(characterstats == true){
characterstats = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
}
else if(characterstats == false){
characterstats = true;
AudioListener.volume = 0;
Time.timeScale = 0;
Screen.showCursor = true;
}
}
}
function Start(){
characterstats = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
}
private var leatherworkingDropDown = false;
private var woodworkingDropDown = false;
private var horsemanshipDropDown = false;
private var cookingDropDown = false;
private var swimmingDropDown = false;
private var woodsmanshipDropDown = false;
function OnGUI () {
GUI.skin = myskin;
GUI.color = Color.blue;
if(characterstats == true){
GUI.Box(Rect(0,0,Screen.width,Screen.height), "Skills Menu");
//woodsmanship menu
if(GUI.Button(Rect(10,160,200,100), "Woodsmanship")){
if(woodsmanshipDropDown == false){
woodsmanshipDropDown = true;
}
else{
woodsmanshipDropDown = false;
}
}
if(woodsmanshipDropDown == true){
swimmingDropDown = false;
horsemanshipDropDown = false;
woodworkingDropDown = false;
leatherworkingDropDown = false;
cookingDropDown = false;
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), "Woodsmanship");
//
if(Input.GetKeyDown("backslash")){
woodsmanshipDropDown = false;
}
}
if(GUI.Button(Rect(10,160,200,100), "Swimming")){
if(swimmingDropDown == false){
swimmingDropDown = true;
}
else{
swimmingDropDown = false;
}
}
if(swimmingDropDown == true){
woodsmanshipDropDown = false;
horsemanshipDropDown = false;
woodworkingDropDown = false;
leatherworkingDropDown = false;
cookingDropDown = false;
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), "Swimming");
if(Input.GetKeyDown("backslash")){
swimmingDropDown = false;
}
}
if(GUI.Button(Rect(10,160,200,100), "Horsemanship")){
if(horsemanshipDropDown == false){
horsemanshipDropDown = true;
}
else{
horsemanshipDropDown = false;
}
}
if(horsemanshipDropDown == true){
woodsmanshipDropDown = false;
swimmingDropDown = false;
woodworkingDropDown = false;
leatherworkingDropDown = false;
cookingDropDown = false;
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), "Horsemanship");
if(Input.GetKeyDown("backslash")){
horsemanshipDropDown = false;
}
}
if(GUI.Button(Rect(10,160,200,100), "Cooking")){
if(cookingDropDown == false){
cookingDropDown = true;
}
else{
cookingDropDown = false;
}
}
if(cookingDropDown == true){
woodsmanshipDropDown = false;
swimmingDropDown = false;
woodworkingDropDown = false;
leatherworkingDropDown = false;
horsemanshipDropDown = false;
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), "Cooking");
if(Input.GetKeyDown("backslash")){
cookingDropDown = false;
}
}
if(GUI.Button(Rect(10,160,200,100), "Cooking")){
if(horsemanshipDropDown == false){
horsemanshipDropDown = true;
}
else{
horsemanshipDropDown = false;
}
}
if(cookingDropDown == true){
woodsmanshipDropDown = false;
swimmingDropDown = false;
woodworkingDropDown = false;
leatherworkingDropDown = false;
horsemanshipDropDown = false;
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), "Cooking");
if(Input.GetKeyDown("backslash")){
cookingDropDown = false;
}
}
}}
any help would be greatly appreciated thanks.
Answer by Julien-Lynge · Mar 20, 2012 at 03:24 PM
It sounds from the error like Unity is complaining that your variable isn't strongly typed: you've defined "var [name]" without defining the type (e.g. "var [name] : [type]") for a number of different variables. It may be that when running in the editor Unity can figure out what type of label to use at runtime, but when compiling it needs to compile the code it doesn't know what to compile for.
You can solve this by defining a type for variable used in the line referenced by the error (e.g. var myVar : string;). You can also set #pragma strict, which forces you to type your variables and avoids this kind of thing in the future. It's a good idea to do this anyway - it will make your code (especially with so many variables as you have here) run faster. See http://unity3d.com/support/documentation/ScriptReference/index.Performance_Optimization.html
By the way, if you use an enum rather than a bunch of variables you can drastically simplify your code. I've reduced your OnGUI() by about 80%. Note that this may not work straight out of the box - I'm a C# programmer, not JS, and I haven't tested this. I just wanted to give you an idea how it could be done.
private enum CurrentDropDown
{
None,
Leatherworking,
Woodworking,
Horsemanship,
Cooking,
Swim$$anonymous$$g,
Woodsmanship
}
private var currentDropDown : CurrentDropDown = CurrentDropDown.None;
function OnGUI ()
{
GUI.skin = myskin;
GUI.color = Color.blue;
if(characterstats == true)
{
GUI.Box(Rect(0,0,Screen.width,Screen.height), "Skills $$anonymous$$enu");
//woodsmanship menu
if(GUI.Button(Rect(10,160,200,100), "Woodsmanship")){
if(currentDropDown == CurrentDropDown.None){
currentDropDown = CurrentDropDown.Woodsmanship;
}
else{
currentDropDown = CurrentDropDown.None;
}
}
//swim$$anonymous$$g menu
if(GUI.Button(Rect(10,160,200,100), "Swim$$anonymous$$g")){
if(currentDropDown == CurrentDropDown.None){
currentDropDown = CurrentDropDown.Swim$$anonymous$$g;
}
else{
currentDropDown = CurrentDropDown.None;
}
}
//[etc - same for all the other buttons]
if(currentDropDown != CurrentDropDown.None){
GUI.Box(Rect(210,0,Screen.width - 210,Screen.height), "");
GUI.Label(Rect(220,70,100,50), "accuracy");
GUI.Label(Rect(220,90,100,50), (accuracy));
GUI.Label(Rect(320,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(220,150,100,50), (accuracyxp));
GUI.Label(Rect(270,150,100,50), ("/"));
GUI.Label(Rect(220,130,100,50), "accuracy xp");
GUI.Label(Rect(530,70,100,50), "fatigue");
GUI.Label(Rect(530,90,100,50), (maxfatigue));
GUI.Label(Rect(530,130,100,50), "fatigue xp");
GUI.Label(Rect(630,150,100,50), (maxaccuracyxp));
GUI.Label(Rect(530,150,100,50), (accuracyxp));
GUI.Label(Rect(580,150,100,50), ("/"));
GUI.Label(Rect(220,190,100,50), "magic");
GUI.Label(Rect(220,250,100,50), "magic xp");
GUI.Label(Rect(220,210,100,50), (magic));
GUI.Label(Rect(320,270,100,50), (maxmagicxp));
GUI.Label(Rect(220,270,100,50), (magicxp));
GUI.Label(Rect(270,270,100,50), ("/"));
GUI.Label(Rect(530,190,100,50), "health");
GUI.Label(Rect(530,250,100,50), "health xp");
GUI.Label(Rect(530,210,100,50), (playerhealth));
GUI.Label(Rect(530,270,100,50), (playerhealthxp));
GUI.Label(Rect(580,270,100,50), ("/"));
GUI.Label(Rect(630,270,100,50), (maxplayerhealthxp));
GUI.Label(Rect(220,310,100,50), "strenth");
GUI.Label(Rect(220,370,100,50), "strenth xp");
GUI.Label(Rect(220,330,100,50), (strength));
GUI.Label(Rect(220,390,100,50), (strengthxp));
GUI.Label(Rect(280,390,100,50), ("/"));
GUI.Label(Rect(320,390,100,50), (maxplayerhealthxp));
GUI.Label(Rect(400,10,100,50), currentDropDown);
//
if(Input.Get$$anonymous$$eyDown("backslash")){
currentDropDown = CurrentDropDown.None;
}
}
}
}
Alright so the link you gave me was awesome. It was the perfect resource, along with your code i think that ive got the problem solved . I really agree with you answer to shorten my code thank you
Your answer
Follow this Question
Related Questions
Loading a scene in game with a GUI 1 Answer
Can't draw a box using Basic GUI 1 Answer
Errors when adding a GUI.Label C# 2 Answers
Can't troubleshoot this GUI bug 3 Answers