Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 05, 2015 at 08:02 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by domwhu777 · Apr 24, 2013 at 06:40 PM · javascriptvariablebooleanvoidbooleans

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;
                }
  
           
 }
 
 }    
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 24, 2013 at 06:50 PM 0
Share

By "line 19" do you actually mean line 19 in this exact code? If so, that depends on what Firearm.weaponStrong is.

avatar image fafase · Apr 24, 2013 at 06:58 PM 1
Share

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.

1 Reply

  • Sort: 
avatar image
1
Best Answer

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?

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image domwhu777 · Apr 24, 2013 at 07:00 PM 0
Share

Yeah I changed it to a label for some reason

avatar image domwhu777 · Apr 24, 2013 at 07:04 PM 0
Share

It works when I put a button in their thanks. That was Just me being stupid :P

avatar image Dave-Carlile · Apr 24, 2013 at 07:15 PM 0
Share

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.

avatar image EliteMossy · Apr 24, 2013 at 07:19 PM 0
Share

Users like this should be warned.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges