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 pizzaa5555 · Aug 03, 2017 at 04:22 AM · tutorialroguelike

For loop in "Writing the Board Manager" 2d Roguelike confusion

There is a line I have been trying to figure out but just can't in the 2d roguelike tutorial writing the board manager:

  for(int x = 1; x < columns-1; x++)
             {
                 //Within each column, loop through y axis (rows).
                 for(int y = 1; y < rows-1; y++)
                 {
                     //At each index add a new Vector3 to our list with the x and y coordinates of that position.
                     gridPositions.Add (new Vector3(x, y, 0f));
                 }
             }



I don't get it because if each time it goes through x and y are added by 1, how can it list every coordinate like (1,2), (1,3) etc if it adds one to x and y at the same time? Wouldn't it be just (1,1), (2,2), (3,3) etc.?

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 HarshadK · Aug 03, 2017 at 04:58 AM

The program first enters outer loop (int x...), gets the value of x for first iteration i.e. x will be 1 in this case then it enters inner loop (int y...). Then the inner y loop finishes all its iteration for value of y. Then again the control is passed to outer loop which goes to next iteration value i.e. x will be 2 and it again enters the inner loop and finishes the inner loop and then control goes back to inner loop and this process is repeated on and on till the end condition is reached.

For example, when the loops start, Enter outer loop => x = 1, instantly enter inner loop => y = 1 This would give us (1, 1) Now inner loop continues while value of x remaining the same i.e. 1. So x = 1 & y = 2 => (1, 2). This will continue till all y values are satisfied. Then x will be incremented => x = 2. And inner loop now starts again from it initial value i.e. y = 1, which now gives (2, 1). Now inside inner loop itself y = 2, which gives (2, 2).

This will get repeated till x reaches its target value. Hope you understand the point.

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 pizzaa5555 · Aug 03, 2017 at 05:03 AM 0
Share

I just realized how stupid I am, thanks!

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

70 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

Related Questions

How does Unity figure out generic component type as Wall in Project: 2D Roguelike tutorial? 0 Answers

In the tutorial of the 2D Roguelike game, where is the player gameobject instantiated in the code? 2 Answers

2D Roguelike - moving onto enemies 3 Answers

Why is the boundary not working? 1 Answer

How to make a slider menu 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