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 Ion Leo · Oct 18, 2014 at 09:10 PM · javascriptlistunity 4

What can i do? Unity no responding when i load a list.

Hello I don't understand what happened. I made a class with static property for manage the level and the sequence of enemy scene. The class is called globalData

I have another class called randomNumbers for calculate random number in a range. These numbers cannot be repeated. the method is called randomScene.

globalData has a private static method call loadingOrderScenes() for load a list.

When I comment the line where add new numbers to the list. The program run well. But when I put this line active. Unity no responding.

I think is because is cyclized.

What can i do?

public class globalData : MonoBehaviour {

 //this property is for manage the sequence of enemy scene
 public static List <int> orderScena;
 // this property manage a level
 public static int Level  = 1;
 // this  property manage the characte for the user. 
 public static int personaje = 2;





 public static void loadingOrderScenes()
 {

     RandomNumbers  NumbersRandom;
     NumbersRandom = new RandomNumbers();
     int cantDatos = 0;
     int number = 0;


 
     orderScena =  new List<int>();
     orderScena.Add(personaje);



     try {


         Debug.Log("it going to  enter  "  +  orderScena.Count);



         while (true) 
         {


             number =  NumbersRandom.randomScene(1,6);



             if (!orderScena.Contains(number))
             {
                 Debug.Log("it is on the While  =  " + cantDatos);

                                      // HERE IS THE PROBLEM..................................
                 //orderScena.Add(number);
                 cantDatos ++;
             
             }

             if ( cantDatos ==  7)
             {
                 Debug.Log("it is on the while  =  " + cantDatos);

                 break;
             }



             
         }

         orderScena.Add(7);

         Debug.Log("is out:  "  +  orderScena.Count);

         



     }
     catch (UnityException e)
     {
         Debug.LogError(e);
     }
 


 }

// this is the other method

     public  int randomScene(int min, int max)
     {
                    int number = 0;

         
             number = Random.Range(min , max);
         

         

          return  number;


     }


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
1

Answer by richyrich · Oct 19, 2014 at 02:07 AM

A problem with your code is that cantDatos == 7, will never happen. The maximum value you send to the random.range is 6, but the documentation shows that the max will never be an output - "unless min equals max". "Returns a random integer number between min [inclusive] and max [exclusive]" http://docs.unity3d.com/ScriptReference/Random.Range.html

Therefore, cantDatos will reach 5 at highest.

A suggestion for starting out (as I am too) is that while(true) is a BAD idea. Always have an extra condition to prevent a lock up

E.g. int counter=0; while(true && counter<1000000) Then increment the counter at the end (inside the loop) counter++; This is still not great programming, but its an easy hack while experimenting

To make your code work without a hang, make the following changes... Comment out line 23. If you don't, cantDatos will only reach 6 during the loop. If you need to keep this, set cantDatos to 1 instead of 0. //orderScena.Add(personaje);

      //number =  NumbersRandom.randomScene(1,6);
      //8 will not be included in the list, but 7 will
      number =  NumbersRandom.randomScene(1,8);
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 richyrich · Oct 19, 2014 at 02:11 AM 0
Share

Incidentally, the reason why it only locks up when you have that extra line of code is because before then, your new value has not been entered into the List, therefore the if-statement continues to execute, even though it found the number before, and so cantDatos is still incremented and exits at the break on reaching 7.

avatar image Ion Leo · Oct 22, 2014 at 12:55 PM 0
Share

Thanks for dedicate your time to answer. I changed my code and used these tips.

And it works !

good day

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

null reference exception problem with generic lists in unityscript (i think...) 1 Answer

Screen record in unity3d 7 Answers

Is there a way to convert a 2d generic list to a string in unityscript 1 Answer

in PlayerNetworkMovement i wanna active a deathpanel but it is not taking gameobject 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