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 AppBite · Aug 25, 2012 at 05:20 PM · javascriptcoroutinefor loop

Loop not executing all code - for in loop

Hi Everyone,

I have a for in loop that doesn't work the same each iteration, code is below. Code is pretty simple, it gets a list of GameObjects, and then calls 1 function as it works through each item in the list of max 12.

What happens instead is very odd.

  • The 1st Loop everything seems to work.

  • The 2nd Loop the calculateMoves() function gets called - BUT the print statements afterwards don't fire. BUT the indexNum = indexNum + 1; does

  • The 3rd --> Last loop, just the Print ".name" part at the top of the loop & the index incrementing happen, it appears like the function call never happens & the print "Done" statement below the function don't execute.

I can't see how it's executing just 3 out of 6 lines in the code on some loops, when it executed all 6 the first go.

This code is NOT within the Update() path so should be a straight execution.

I'm a bit mystified as to what is going on.
- The calculateMoves() is being called as some type of co-routine and the loop isn't waiting for it to return ?
- Perhaps I have some mistake with the scope of the local/public variables ? as I am mixing them, bad form but I'm making calculations to build a global grid.

 function getRedTeamMoves() : int {
     var RedTeamList = GameObject.FindGameObjectsWithTag("RedTeam");
     var statusTM : int;
 
     indexNum = 0;
 
     for (RedTeamMember in RedTeamList)
     {
         print ("RedTeamMember.name = " + RedTeamMember.name);
          
         statusTM = calculateMoves(RedTeamMember);
 
         print ("****** Calculations Done for this bot *************");
         print ("*******************");
 
         indexNum = indexNum + 1;
         print ("indexNum = " +indexNum);
             
     }
     return 1;
     
 }

Any help appreciated, hopefully it's something really silly.

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 kag359six · Aug 25, 2012 at 05:46 PM 0
Share

is indexNum returning the right number?

1 Reply

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

Answer by Eric5h5 · Aug 25, 2012 at 05:48 PM

Turn off "collapse" in the console.

Comment
Add comment · Show 1 · 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 AppBite · Aug 29, 2012 at 02:33 PM 0
Share

Thank you! That's bitten me before when debugging. Collapse was masking a bug in my code where the function kept calculating the same values every time even when the inputs were different.

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

10 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

Related Questions

changing a coroutine's argument at the coroutine's runtime? 1 Answer

Coroutine gets skipped in javascript/unityscript 0 Answers

Stop coroutine not working 1 Answer

Getting For Loops to work in a Coroutine 0 Answers

Simple for loop to change QualityLevel 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