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 PemuG · Jul 23, 2013 at 01:30 PM · variablebooleanfindreal-timestatus

How to find variable status?

So when I have 3 variable for example:

 var variable1 : boolean = true;
 var variable2 : boolean = true; 
 var variable3 : boolean = false;

How (in script, in real time) find the variable which have a false status?

Thanks in advance ;)

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 KiraSensei · Jul 23, 2013 at 02:01 PM 0
Share

You mean that you are sure that at anytime in your code, only exactly one of the three variables would be false ?

In that case, you can have just :

 if (!variable1)
 {
     ...
 }
 else if (!variable2)
 {
     ...
 }
 else if (!variable3)
 {
     ...
 }

But I'm not sure this is what you really want ...

avatar image PemuG · Jul 23, 2013 at 02:37 PM 0
Share

I want to loop find a variable, which have a false status.

avatar image CHPedersen · Jul 23, 2013 at 02:41 PM 1
Share

You cannot "loop find" a variable or an object that isn't stored in a collection over which you can have code loop. All three of your variables are singles.

Put the booleans in a List, then call IEnumerable.FirstOrDefault to find the first boolean in the list whose value is false. I can write you an example, but it would be in C#, not UnityScript. Is that still of use to you?

1 Reply

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

Answer by amphoterik · Jul 23, 2013 at 02:45 PM

You will need to change your code up a bit to do what you want. First off, the variables will have to be stored in an array. Try the following:

 bool [] values;
 
 void Start()
 {
     values = new bool[3];
     values[0] = true;
     values[1] = true;
     values[2] = false;
 }

Then, somewhere in your code (wherever you need it) you can find the false variable like this:

 foreach (bool value in values)
 {
     if(!value)
     {
         //this is the one you want;
     }
 }
Comment
Add comment · Show 2 · 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 PemuG · Jul 23, 2013 at 03:06 PM 0
Share

Ok, thanks ;)

avatar image amphoterik · Jul 23, 2013 at 03:11 PM 0
Share

If this helped you find the answer, please select it as the answer. It helps future readers and gives you karma.

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

Toggle Boolean Function 2 Answers

Boolean not switching? 2 Answers

Change a Variable with another script not working (C#) 4 Answers

Yield Waitforseconds not working at all 3 Answers

ANOTHER Boolean Problem 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