Log In  

Hey folks! First post, here.

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.

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.

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.

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:

(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

Vs:

(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

Any help would be muchly, muchly appreciated. Thanks!

P#79286 2020-07-14 00:39 ( Edited 2020-07-14 00:43)

2

I doubt that change alone is causing troubles.
Are you sure you don’t manipulate stage.spire elsewhere in the game?
Try to print variables to make sure they have correct values.

P#79306 2020-07-14 10:18 ( Edited 2020-07-14 10:23)

Thanks! It turned out not to be the value of the variable, but seemed to just be the straw that broke the camel's back... I was using a very inefficient function for positioning the other characters on the field, I've disabled that function for now and now the table variables cause no problem. Still strange though, I guess I'll have to do some optimization.

P#79360 2020-07-15 21:05

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 13:12:43 | 0.006s | Q:9