Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 xGreyFoxx · Mar 31, 2014 at 12:05 AM · endless loop

Problem with while loop looping infinitely

Okay my while loop is going on forever and im not sure why. This is the list I am accessing in this script

 public List<int> usedTiles = new List<int>(); 


And here is the while loop within the other script. Everything is linking properly as far as I know but it simply loops forever. There must be something very obvious that I am not seeing but I'm sure you guys will.

 int tileIndex = UnityEngine.Random.Range (0, 8);
 while (levelGenerator.usedTiles.Contains (tileIndex))
 {
      tileIndex = UnityEngine.Random.Range (0, 8);
 }         
 
Comment
Add comment · Show 28
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 Lo0NuhtiK · Mar 31, 2014 at 12:09 AM 0
Share

public List usedTiles = new List();

<--That isn't giving you some kind of error to start with? What is usedTiles a List<of> ?

Edit : Never$$anonymous$$d. Thanks for editing your post. 101/010 code button is a pain in the ass sometimes.

avatar image xGreyFoxx · Mar 31, 2014 at 12:13 AM 0
Share

there we go, sorry. First time posting and didn't sere how to include code at first

avatar image Lo0NuhtiK · Mar 31, 2014 at 12:23 AM 1
Share

Here's a link to a random-exclude topic :

http://answers.unity3d.com/questions/452983/how-to-exclude-int-values-from-randomrange.html

The way you have it now, if your [usedTiles] has {0,1,2,3,4,5,6,7} in it then it's going to keep going forever because it'll always generate one of those numbers.

avatar image xGreyFoxx · Mar 31, 2014 at 12:30 AM 0
Share

Well thats the thing, I understand that it would loop forever with those numbers. But I have it empty. I expect that it would loop forever after exhausting its options, but it seems to loop before doing anything, it doesnt appear to do anything before crashing. Is it because it has nothing declared to it? cause, as i understand it, i've left it empty.

avatar image Lo0NuhtiK · Mar 31, 2014 at 12:33 AM 0
Share

You didn't assign anything to it in the inspector either??

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by soulblade · Apr 04, 2014 at 12:03 PM

Try listing your code in the update() function and change 'while' to 'if' that should automatically update the code and test if the used tiles contains the tile index. Hope this helps

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

26 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

Related Questions

Audio Quality + Tiny Delay 1 Answer

Enviroment gets increasingly brighter when running 0 Answers

www class blocks script execution 1 Answer

Endless while loop in coroutine which uses condition changing in Update() function. 2 Answers

Problem with HashSet 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