Thread Tools Display Modes
01-12-11, 01:45 PM   #1
zynix
A Cliff Giant
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 70
Working with tables

Hello, I am trying to make a function for my AddOn, that allows me to reset the position of the unitframes.
It's almost working.
Pastebin link
The problem is that I have 2 tables with information:
Position and Defaults.
These both get filled with some info on 6 frames position.
The Defaults table is the one used for the resetting of the frames. (See lines 74 - 104 in pastebin)
While the Position table is used for retrieving the position upon login.
The "Reset to default" functions execute properly when clicking the reset button. (See 107 - 134 and 487 - 495 in pastebin)
But the frames does not move to their original position.

The problem lies in that the Defaults table gets filled with the same info as the Position (55 - 62, 283 - 377)
As you can see, when the initialization script begins, the Position and Defaults will get the same values put into them.
But when the frames are moved, and the SaveToDB function executes, it puts those values into both, even though it should only do it in one of the table (Position)


Are there anyone who is willing to help me?

Last edited by zynix : 01-12-11 at 01:49 PM. Reason: Grammar
  Reply With Quote
01-12-11, 07:09 PM   #2
kraftman
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 63
Line 78, why are you saving the positions after you set them to default?

as a side note, try to avoid using global varianles when possible, and when you have to use them because they are savedvariables, try and give them a unique name so that they are less likely to interfere with other addons.
  Reply With Quote
01-13-11, 01:34 AM   #3
zynix
A Cliff Giant
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 70
Originally Posted by kraftman View Post
Line 78, why are you saving the positions after you set them to default?

as a side note, try to avoid using global varianles when possible, and when you have to use them because they are savedvariables, try and give them a unique name so that they are less likely to interfere with other addons.
That is because if i dont do so, then the frames will move back to the other position (the one before pressing the reset button).

I press the button, get the contents of the Defaults table, use the values to set the position of the frames. If i dont save the position, then the Position table wont know that the frames have moved, and therefore it'll be "outdated" and position the frames at the wrong place.

About the local/global variables. Do you mean the tables created in the initialization script?
The init frame is created as a local, then shouldn't everything done from within that frame, be local?
  Reply With Quote
01-13-11, 02:45 AM   #4
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Both Position and Defaults are global, which isn't that great. This is easily remedied by adding
Code:
local Position, Defaults
at the top. This will make them local to your addon without breaking your later checks (e.g. if not Position then).

EDIT: As for your actual problem.. here's my take on it from glancing at the code.

In your function init() you check if Position is nil and if it is you make a new table. You then go on to compare this table against your defaults in SavedVar. Now since Position isn't defined anywhere prior, it will always be nil always resulting in a new table which will always evaluate false compared to SavedVar and thus Position is filled with those values.

Then the same thing happen with Defaults. So in the end both tables contain the same information.

(Side-note: the variable table passed to SaveToDB() doesn't seem to be used)
__________________
Oh, the simulated horror!

Last edited by Ailae : 01-13-11 at 02:53 AM.
  Reply With Quote
01-13-11, 03:09 AM   #5
zynix
A Cliff Giant
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 70
Originally Posted by Ailae View Post
Snip

(Side-note: the variable table passed to SaveToDB() doesn't seem to be used)
Well, the SaveToDB() function has worked with the prior versions of my AddOn, the variables update as intended. By the way, in the TOC file, I have declared Position and Defaults as SavedVariables, so the check for the tables should only say nil once.

TOC code:
Code:
## Interface: 40000
## Title: Zynix unitframes
## Author: Zynix
## Notes: For my unnamed friend, Unnamed. Credit to Mischback, for being awesome, and for helping with the code.
## SavedVariables: Position, Defaults
## Version: 1.5
core.lua
  Reply With Quote
01-13-11, 03:33 AM   #6
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
You really should change those variable names, since those exist in the global namespace. Or at least add a unique prefix.

Guess I'm not seeing what's wrong then.. but what is the use of the table Defaults though? Isn't it supposed to be the same as SavedVar anyway?
__________________
Oh, the simulated horror!
  Reply With Quote
01-13-11, 09:53 AM   #7
zynix
A Cliff Giant
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 70
Originally Posted by Ailae View Post
You really should change those variable names, since those exist in the global namespace. Or at least add a unique prefix.

Guess I'm not seeing what's wrong then.. but what is the use of the table Defaults though? Isn't it supposed to be the same as SavedVar anyway?
So, you're saying that I can acces the SavedVar the exact same way as Defaults?

Well, that enlightened my mind :P

I'll see if it works tomorrow
Thanks
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Working with tables


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off