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 JChilton · Nov 23, 2013 at 12:48 AM · string2d arrayrecursion

String[,] returns wrong value in recursion

Hi there, I seem to be having a strange issue with recursion and my 2D array. Here's a simplified version of my code that gives the same issues.

puzzle[,] is a string[15,15] with filled values. Calling any form of puzzle[x,y] returns the correct value. The loop below always prints out the first value found, e.g. if I call PrintItem(3), it will always print out the value found in puzzle[3,1] despite Debug.log(x) will print 3, then 4, then 5, etc...

 void PrintItem(int x){
     Debug.Log(puzzle[x,1]);
     Debug.log(x);
     x++;
     if(x < 10){
         PrintItem(x);
     }
 }

geting any puzzle[x,y] outside this function returns the correct value. but in this loop the debug of puzzle[x,y] always returns the same value, even though just loggin x will print out incrementing values.

The array itself is solid, looping through all items outputs the correct values in each cell.

Any thoughts?

edit: replaced example with an even simpler example

edit: using a jagged array produces same results

Comment
Add comment · Show 2
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 Huacanacha · Nov 23, 2013 at 01:17 AM 1
Share

Can you show the actual puzzle declaration, how you fill puzzle, and the actual PrintItem function? Or even better a fully working snippet of code that demonstrates the problem. There's too many unknowns with what you have provided, plus the code as shown isn't valid... puzzle declaration is just a comment, Debug.log (lowercase 'l') doesn't exist etc.

avatar image JChilton · Nov 23, 2013 at 01:33 AM 0
Share

The comment under the snippet says that everything prints out correctly if I call puzzle[3,1], puzzle[1,5] or any other variation of puzzle[x,y]. I'll remove those 'declarations' from the snippet as to not confuse anyone else.

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Longest Common Subsequence Recursive Function Error. 1 Answer

replacing a character in a String 1 Answer

returning a variable in javascript 1 Answer

set Strings parts in different colors 1 Answer

www.data and string conversion to integer 2 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