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 /
avatar image
0
Question by Kobohdashi · Aug 26, 2013 at 09:02 AM · inventoryitemsprogress bar

Trying to pick one or the other

I have 2 progress bars one for hunger one for thirst. I pick up two different items, item 1. is water item 2 is food after I pick them up they go into the inventory when I open the inventory I see both items the problem is when I click to use the water both the thirst bar and hunger bar go up. The way it should work is if I click to use water then only the water bar should go up and if I click to use the food only the food bar should go up. Here is the script can anyone tell me what I am doing wrong?

 function UseEffect () 
 {   if (Thirst.tcurHP == true && Hunger.fcurHP == false);
     {
         Thirst.tcurHP += 25;
     }
      if (Thirst.tcurHP == false && Hunger.fcurHP == true);
     {
         Hunger.fcurHP += 25;
     }

 
Comment
Add comment · Show 3
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 getyour411 · Aug 26, 2013 at 09:07 AM 0
Share

On the first if, you use Hunger.fcurHP as a boolean (true/false), as you do in the second if, but then you use Hunger.fcurHP as an int so something is wrong there.

avatar image Kobohdashi · Aug 26, 2013 at 09:18 AM 0
Share

That's what I don't know how to do, how do I set up the boolean so that if I pick the water in the inventory only the thirst bar goes up? and vise versa if I pick the food then only the food bar goes up?

avatar image mattssonon · Aug 26, 2013 at 09:21 AM 0
Share

You're using the same variables as both booleans and integers, make them separate.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Hoeloe · Aug 26, 2013 at 09:25 AM

I'm not sure what those variables are. Is Thirst.fcurHP the current thirst level, and Hunger.fcurHP the hunger level? If so, you should learn about types. In most languages, variables can only be one type at once - and in this case, yours are an integer, or int. When you compare something to true or false, it has to be a boolean type. The problem you're having here is that you're using what's called an "implicit cast". You can convert variables from one type to another, and sometimes you can do so without explicitly stating that you want to. In this case, int can be implicitly converted to boolean by assuming 0 = false and any value greater than 0 is equal to true. Thus, your tests are fallacious. You need to set a different flag when you select the object, which determines which object you've just selected. The reason both bars go up is that you're actually testing the levels of the thirst and hunger, not what item you're using, which is what you need to do.

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 Hoeloe · Aug 26, 2013 at 09:45 AM 0
Share

Typing is a very important aspect of any program$$anonymous$$g, so you should really have a solid understanding of it before you venture into any program$$anonymous$$g.

avatar image Hoeloe · Aug 26, 2013 at 10:14 AM 0
Share

There's one here I found after a quick search for beginner typing tutorials, it might help: http://www.youtube.com/watch?v=VLBC5$$anonymous$$IZWN8

avatar image getyour411 · Aug 27, 2013 at 02:16 AM 1
Share

To further clarify from your 1st example, something like

 if(item.name == "Water")     Thirst.tcurHP += 25;
 if(item.name == "S$$anonymous$$k")      Hunger.fcurHP += 25;

or more likely something like if(item.type == "Drink") so that you don't have to explicitly name everything, but that leads into Enum, Lists, and a whole enchilada

avatar image Kobohdashi · Aug 27, 2013 at 04:12 AM 0
Share

@getyour411 $$anonymous$$uchas gracias

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image

Related Questions

How to make an inventory for my text advenutre? 0 Answers

How to set up a gui text box to count inventory items? 1 Answer

Equipting a Item/Weapon 1 Answer

Database error updating inventory 0 Answers

Using enums to design an inventory system? 1 Answer


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