View Single Post
11-05-08, 10:51 AM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
that last part confused me, where assigning a new value to the existing var still returned the old value, but...

I will look into metatables. I haven't worked with them yet. Just to clarify, my issue was with creating new options during development. Say I had

Code:
defaults = {
     scale = .9,
     fontsize = 14
}
Then, in my PEW function I put
Code:
MYMODDB = MYMODDB or defaults
That would make
Code:
print(MYMODDB.scale)
return .9

After playing with the code for a while, I decide I want to add an alpha option as well. So my defaults table changes to this
Code:
defaults = {
     scale = .9,
     fontsize = 14,
     alpha = .7
}

...

MYMODDB = MYMODDB or defaults
And somewhere in the code I have
Code:
f:SetAlpha(MYMODDB.alpha)
But, upon reloading the UI to pick up the changes made to the lua, I would get an error for
Code:
f:SetAlpha(MYMODDB.alpha)
because
Code:
print(MYMODDB.alpha)
would return nil


I probably didn't need to explain myself, as I'm sure you knew what I meant, and I will read up on metatables. Thanks, Slakah.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote