leVerDreaM [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=45404 Too many tables? <p>Hey folks! First post, here.</p> <p>I just started learning Lua this summer, and the use of tables has been a big hurdle to me. I seem to have the basic concept worked out, but something really weird is happening to my one project.</p> <p>Long story short, I'm making a racing game that is fairly code-intensive when it comes to the graphics. It was working just fine, until the other day when I started working on a level-select feature. I changed one of the level parameters from a solo variable to a part of a table, so that I'd be able to group the various parameters into nested tables and swap them with a simple level index, but suddenly, the performance took a nose-dive. I don't mean dropped frames, I mean it slowed down to a fraction of the acceptable frame rate, seemingly down to 5 frames a second or less.</p> <p>I changed that one variable back to a standalone variable, performance jumped back to normal. Changed it back to an entry in a table, and the game slogged back down to a few frames a second.</p> <p>I know there's a lot I still don't know about using tables, but does anyone know of any hard limit that would abruptly cause performance to suffer this drastically? All I changed was this:</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>(in _init:) stage={addr=0} spire=1 (in _draw:) spr(5,64+rel_x,56-(spire*8)) for y=1,spire do spr(6,64+rel_x,64-(y*8)) 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>Vs:</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>(in _init:) stage={addr=0,spire=1} (in _draw:) spr(5,64+rel_x,56-(stage.spire*8)) for y=1,stage.spire do spr(6,64+rel_x,64-(y*8)) 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>Any help would be muchly, muchly appreciated. Thanks!</p> https://www.lexaloffle.com/bbs/?tid=38810 https://www.lexaloffle.com/bbs/?tid=38810 Tue, 14 Jul 2020 00:39:40 UTC