Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Divinitize1 · Oct 13, 2019 at 12:00 AM · arraylistchecklooping

Need some help with Array searching logic

I have an array of strings which is 42 in length. I also have an array of GameObjects which is 50 in length.

Inside a coroutine, I am picking a random int up to the length of the string array. I am then checking that string against the GameObjects name inside the GameObject array. I can easily figure out how to check if something exists, and if it does, restart the coroutine until it finds one that doesn't exist. The problem I have is that I cannot figure out the logic for if there are no more Strings in the array that DO NOT match the GameObject array from then I want to call another function. I have also tried moving this to a loop but whatever I try I am running into a stack overflow. I'm not the best at explaining things so I hope this makes sense, I will snippet what I think is important below.

 IEnumerator _Continue()
 {
 int pickRandom = Random.Range(0, STRINGARRAY.Length);
 if(GAMEOBJECTLIST.IndexOf(GameObject.Find("blah/blah/bah/blah/" + STRINGARRAY[pickRandom])) < 0) //Doesn't Exist
 {
 //DO STUFF HERE
 }
 if(GAMEOBJECTLIST.IndexOf(GameObject.Find("blah/blah/bah/blah/" + STRINGARRAY[pickRandom])) > 0) //If it does exist
 {
 StartCoroutine(_Continue()); //Restart the coroutine
 }
 }

It's here that I am getting stumped, I cannot seem to find a way to stop and run something else if All of the strings (which are the GameObject names) exist and therefore I no longer need to check.

Any help would be appreciated, I should mention that the GameOBject[] is a List and the String[] is an Array.

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

1 Reply

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

Answer by GrayLightGames · Oct 13, 2019 at 03:58 AM

I think what you're saying is that if all of the strings in your STRINGARRAY match GameObjects' names, you want to stop calling _Continue and do something else right? I don't know your architecture, but you could make a copy of the STRINGARRAY and use the copy to do this operation. You would then remove checked names from it on each iteration. So if it finds a GameObject name match, that name is removed from the array and it never checks that one again. Eventually, the STRINGARRAY will be empty, which is the case you're looking for. Your coroutine would first have a check if the STRINGARRAY is empty, so you could break out there, and if it's not empty, do what you have already coded. Follow? This would also cut down some of the redundancy as you're not randomly checking the same name twice. _Continue would be called 42 times only.

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 Divinitize1 · Oct 13, 2019 at 04:26 PM 0
Share

Thanks for the reply, that sounds like a good idea that should work, I'll remove each one from the string array once it is "used" and check if it's empty. Thanks!

avatar image GrayLightGames Divinitize1 · Oct 13, 2019 at 06:58 PM 0
Share

Great glad I could help. Good luck with your project!

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

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

Related Questions

Lists: Avoiding ArgumentOutOfRangeException: Argument is out of range errors 1 Answer

i need a player list help please 0 Answers

unique list of 10 random numbers 4 Answers

How do I check for strings in an array to match up with the index of another array? 1 Answer

A node in a childnode? 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