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 Rebel8909 · Aug 09, 2014 at 08:26 PM · javascriptbooleancoordinates

How to have a Boolean check as true after multiple other Booleans are marked true

So I'm making a puzzle game and I was thinking of using a system where the puzzle pieces would check a boolean on a script when their coordinates matched up with the slot they're supposed to be in. Something like:

 var NextLevel : Boolean;
 var PosCorrect : Boolean
 var P1 : GameObject;
 var S1 : GameObject;

 function Update(){
 if(P1.position = S1.position)(
 
 PosCorrect = true
 }
 
  if(multiple boolean = true){
     
     NextLevel = True;
     
     GUI();
     }
     
 

And then I would have a GUI button show up that when clicked would let the player go onto the next level. Is there anyway to do this? And if there is how so.

Comment
Add comment · Show 1
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 rutter · Aug 09, 2014 at 08:23 PM 0
Share

You can check multiple conditions using the "Logical And" operator, &&:

 if (condition1 && condition2) {
     doSomething();
 }

If you have an array, you could check them using a loop:

 var success = true;
 for (var myBool in myBoolArray) {
     success = success && myBool;
 }
 if (success) {
     doSomething();
 }

If you need more than that, it might help to clarify your data structure. How are you getting these booleans? Where are they co$$anonymous$$g from?

If branching or looping/arrays are new to you, now is probably a good time to look up some tutorials.

2 Replies

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

Answer by Kiwasi · Aug 09, 2014 at 08:35 PM

Use properties. In C# (I'm sure JavaScript has equivalent methods).

 private bool[] boolArray;
 private bool multiBool {
     get {
         for (int i = 0; i < boolArray.length; i++){
             if (!boolArray[i]){
                 return false;
             }
         }
         return true;
     }
 }

Checking multiBool will automatically loop through each bool in boolArray and only return true if all of the bools in the array are true.

Comment
Add comment · Show 3 · 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 Rebel8909 · Aug 10, 2014 at 02:00 AM 0
Share

Ok so when the multiBool is checked it checks all the other bools? And if they are all true then it ticks it as true.

I'll look into that thanks :D

avatar image KellyThomas · Aug 10, 2014 at 02:06 AM 1
Share

It looks like there is a $$anonymous$$or typo that may cause confusion: Properties have both set and get accessors. If wanting to read the value then line three should be:

     get { 
avatar image Kiwasi · Aug 10, 2014 at 02:22 AM 1
Share

Fixed. Nice catch.

$$anonymous$$y intention was to leave out the set as it has no meaningful implementation in this context.

avatar image
0

Answer by Graham-Dunnett · Aug 09, 2014 at 08:32 PM

I'd think I'd have two static arrays Matched and UnMatched. Add all the puzzle pieces to the UnMatched array when you start up. (Perhaps in Start() for each game object.) Then as the player moves a piece to the right location, move the game object from the UnMatched array to the Matched array. You can then have code that looks at the number of entries in the UnMatched array. Once it falls to zero, you know you have all the pieces in their correct locations.

See:

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/statics

if you need help understanding why the arrays should be static.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

boolean questions get, set, in java. 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Else and If 2 Answers

Pause Button Help 2 Answers

animation not working 0 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