tsgibbs [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=53503 Problematic Behavior Accessing Multi-dimensional Array <p>Hello, hopefully I've posted this in the correct area, the BBS is a little confusing.</p> <p>The three lines below are really troubling me.<br /> The first one demonstrates that we have access to i, x, and y.<br /> The second one demonstrates that we have access to a[1][1][1].<br /> The third one should evaluate to a[1][1][1] which we have access to and stores the value &quot;0&quot;, but instead it crashes.</p> <p>The code:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>print(i..x..y) -- returns &quot;111&quot; print(a[1][1][1]) -- returns &quot;0&quot; which is the correct value stored there print(a[i][x][y]) -- error</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>The error:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>print(a[i][x][y]) -- error attempt to index field &quot;?&quot; (a nil value)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Does anyone know why it works this way? Any advice on the correct syntax? I can post the full code if needed, but it's somewhat obfuscated in favor of fewer characters.</p> <p>Thanks for reading!</p> https://www.lexaloffle.com/bbs/?tid=42548 https://www.lexaloffle.com/bbs/?tid=42548 Tue, 20 Apr 2021 01:44:41 UTC