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 MountDoomTeam · Oct 03, 2012 at 08:15 PM · arrayvaluecompareoncemany

Take only one action ~ if(A = var[i]) reveals a true

Sorry noob question! I'm comparing a gameobject transform to all transforms in an array. if not equals to any values in array, i just want to take an action 1 time, i only know how to do it as many times as i do the comparison:

 for (var marker in markers)
 {
 if ( pos = marker) //return true if 1+ value is same and do just one
 {Instantiate(obj,pos,rot);}

Comment
Add comment · Show 7
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 AlucardJay · Oct 03, 2012 at 08:21 PM 0
Share

untested theory

 for (var i:int = 0; i < markers.length; i ++)
 {
     if ( markers[i] == pos )
     {
         Instantiate(obj,pos,rot);
         i = markers.length + 1; // fall out of the loop
     }
 }
avatar image mikebelotti · Oct 03, 2012 at 08:22 PM 0
Share

I think the keyword you're looking for is "break". Try putting a "break;" right after your Instantiate call to quit out of the loop.

avatar image Fattie · Oct 03, 2012 at 08:23 PM 0
Share

sure you don't mean

==

rather than

=

here's how you write such a function

 function doesNOTcontain() // return TRUE if NO matches
 {
 for each of them ...
    {
    is it a match?  if so return FALSE
    }
 // here, it must be that there are NO $$anonymous$$ATCHES, so...
 return true;
 }

it's sometimes hard to hop in to program$$anonymous$$g unless you have a deep background in, well, program$$anonymous$$g! $$anonymous$$eep it up!

it takes years and years and years and years to absolutely master all these maybe 1000 basic algorithms you must "see" instantly to work

avatar image Fattie · Oct 03, 2012 at 08:28 PM 1
Share

@alu dude, you totally have to get with BREA$$anonymous$$ and CONTINUE

very confusing if you are new, since you always mix 'em up.

you should never, ever write this inline though.

make a little function that returns (it "breaks" with a return, essentially)

(of course, your comp sci professor told you "only ever have one point of return!". he's totally correct, but he can also go to hell.)

avatar image Fattie · Oct 03, 2012 at 08:40 PM 1
Share

"I am self-taught" michael jackson, paul mccartney and mozart are self-taught so don't worry about that.

"surprised I have never seen it in one of the eleventeen million loops I have read..." that's because everything on the internet is crap :)

Show more comments

1 Reply

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

Answer by AlucardJay · Oct 03, 2012 at 08:27 PM

With great help from @mikebelotti :

 for (var i:int = 0; i < markers.length; i ++)
 {
     if ( markers[i] != pos )
     {
         Instantiate(obj,pos,rot);
         break; // fall out of the loop
     }
 }
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 Fattie · Oct 03, 2012 at 08:31 PM 0
Share

alu dude (I THIN$$anonymous$$) your answer is THE OPPOSITE of what he's asking

"if NOT equals to ANY values in array" ....

i THIN$$anonymous$$ that's what the bloke meant

what this site needs is a £$@ing proofreader -- any language would do! -- for new questioners! heh

avatar image MountDoomTeam · Oct 03, 2012 at 08:33 PM 0
Share

Thanks everyone! i programmed DSP with native instruments Reaktor, then dragon naturally speaking automation macro's, then winamp milkdrop presets, and i was always confused by program$$anonymous$$g, and now i can read it O$$anonymous$$ although and can write some kinds of games thanks to all you! i am just makign a dungeon generator it's to compare if the tunneller is in a new space in the array :)

avatar image AlucardJay · Oct 03, 2012 at 08:35 PM 0
Share

You are absolutely right, reading the question rather than going off the code reveals this. I think I was thrown by the same thing as you mentioned, (is equal to only represented as = , but it now looks like it was is not equal to != )

I shall amend the answer accordingly, thankyou for your help. Regarding proofreading, am a bit blurry-eyed at this hour so that would be quite handy =]

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

12 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

Related Questions

Check if all elements of an array contain the same value? 3 Answers

Pass value from several objects into one JS 1 Answer

Add values to Int[] (SetTriangles) 1 Answer

How to get the key from Array value 1 Answer

Comparing two objects properties for the closest 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