- Home /
The question is answered, right answer was accepted
void cannot be used in a boolean context
Please help it says that for line 19. Please help :D var bool : boolean = false;
function Update () {
}
function OnGUI () {
// This draws a button in the left top corner of the screen which says Player Stats and if you click on it it changes the boolean bool to the opisite to what it is at the moment
if (GUI.Button (Rect (Screen.width - 90, 0, 100, 20), "Player Stats")) {
bool = !bool;
}
// Draws the stats box ad labels if the boolean bool is true;
if(bool) {
GUI.Label (Rect ( Screen.width / 2 - 175, Screen.height / 2 - 300, 350, 350), "Stats"); // This draws a large GUI box with the word "Stats" at the top
GUI.Label (Rect (Screen.width / 2 - 170, Screen.height / 2 - 275, 350, 350), "Health: " + PlayerHealth.curHealth); // The draws a HUI label which displays the players health
GUI.Label (Rect (Screen.width / 2 - 170, Screen.height / 2 - 260, 350, 350), "Weapon Strength: " + Firearm.weaponStrong); // This draws a GUI label which displays the weapon strenght
GUI.Label (Rect (Screen.width / 2 - 170, Screen.height / 2 - 245, 350,350), "Ammo : " + Firearm.Ammo); // This draws a GUI label which show the play how much ammo they have
if (GUI.Label (Rect ( Screen.width / 2 - 170, Screen.height / 2 - 230, 150, 150), "Upgrade Weapon Strenght"))
{
Firearm.weaponStrong += 5;
}
}
}
By "line 19" do you actually mean line 19 in this exact code? If so, that depends on what Firearm.weaponStrong is.
As I removed my wrong answer, Eric5h5 comment is gone with it but here it is again since it makes some sense:
"bool" is not used as a reserved word in Unityscript, so technically you can use it as the name of a variable. It's a very bad variable name though; something actually descriptive of what it does should be used ins$$anonymous$$d.
Answer by Dave-Carlile · Apr 24, 2013 at 06:52 PM
You're executing GUI.Label
as if it returns a boolean value. It doesn't return a value at all, so you can't use it in an if
statement.
if (GUI.Label (Rect ( Screen.width / 2 - 170, Screen.height / 2 - 230,
150, 150), "Upgrade Weapon Strenght"))
{
Firearm.weaponStrong += 5;
}
The GUI.Label documentation makes this clear. Do you mean to have a button here?
It works when I put a button in their thanks. That was Just me being stupid :P
Looks like you've asked quite a few questions that have answers that you haven't accepted. You should go through them and accept answers that were helpful to you.
Follow this Question
Related Questions
How to stop a boolean from going back to false 1 Answer
Yield Waitforseconds not working at all 3 Answers
Unity says there is no such thing as a boolean. 1 Answer
Static Variable Problem 1 Answer
Change Variable on Another Script 2 Answers