chidori [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=12384 Collisions of objects(tables) within a shared table? <p>Hello,<br /> I'm doing some Lua pseudo-OOP stuff, and I want to check if tables within a shared table are colliding.<br /> I have a simple AABB check-collision function that takes the x, y, width, and height of two objects and returns true or false if they're intersecting or not.</p> <p>I'm assuming I should loop through the main table like so</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> FOR K,V IN PAIRS(DUDES) DO IF CHECK_COLLISION(V.X,V.Y,V.W,V.H ... THEN DO_STUFF() END END </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I'm not sure how to reference a value of the next table from the same table. I've tried</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> IF CHECK_COLLISION(V.X,V.Y,V.W,V.H,DUDES[K+1].X,DUDES[K+1].Y,DUDES[K+1].W,DUDES[K+1].H </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>and a few similar methods, but none of them seem to work. I think I'm headed in the wrong direction, but I can't figure it out. Do I need to do some nested looping to index each table DUDE within DUDES, or use a different method from pairs?</p> https://www.lexaloffle.com/bbs/?tid=3168 https://www.lexaloffle.com/bbs/?tid=3168 Sat, 26 Mar 2016 18:37:56 UTC