Prior to sending my game OmniBlaster to the Apple for review, I started getting an error something like:
Too many local variables.
Seems there is a 200 variable/local function limit to a given Lua chunk.
Since I was/am still new to the language and I’m not comfortable with the event system to get things I need during event processing passed in, I end up using variables in a global variable like configuration.
Knowing that globals are performance problems, I put local in front of everything: variables and functions. Well right up until I hit that limit. Aftewards I just left things without the word local in front of it and took whatever performance hit I am going take.
So now I’m working on version 1.1 and I’m starting to refactor things. While I doubt I will get very object oriented being that I’m an old school procedural guy so what I’m doing is creating a series of tables to objectify my bazillion “globalish” variables like this:
local powerUp = {}
powerUp.isInvincible = false
powerUp.superShieldTween = false
powerUp.hasMegaBlasters = false
powerUp.megaBlasterTimer = nil
powerUp.megaShieldTimer = nil
powerUp.hasMegaTorpedoes = false
powerUp.megaTorpedoCount = 5
powerUp.megaShield = nil
So I only use one of my precious 200 local variables to cover bunches.
My question is this: Am I going to take a performance hit for this? Is this the way I should be doing this anyway?
Rob
[import]uid: 19626 topic_id: 10629 reply_id: 310629[/import]