-
Posted by Taborious on Fri, 20 Mar 2009 14:03:44
I want to create a small addon that will notify me when someone has changed gear. Simple registration of unit_inventory_changed and when it fires, get the toons name and populate a fontstring on a frame. My question is as long as the frame is open does a variable stay populated or saved?
if i have a variable peopleChangingGear and each time unit_inventory_changed fires I add that person's name to the variable. e.g.
peopleChangingGear = peopleChangingGear .. newNiinjaName
fontString:SetText(peopleChangingGear)
How long does peopleChangingGear stay populated? forever? until the frame is closed? on UI reload? -
Posted by Taborious on Fri, 20 Mar 2009 14:03:44
I want to create a small addon that will notify me when someone has changed gear. Simple registration of unit_inventory_changed and when it fires, get the toons name and populate a fontstring on a frame. My question is as long as the frame is open does a variable stay populated or saved?
if i have a variable peopleChangingGear and each time unit_inventory_changed fires I add that person's name to the variable. e.g.
peopleChangingGear = peopleChangingGear .. newNiinjaName
fontString:SetText(peopleChangingGear)
How long does peopleChangingGear stay populated? forever? until the frame is closed? on UI reload? -
Posted by jnwhiteh on Sat, 21 Mar 2009 05:11:55
I want to create a small addon that will notify me when someone has changed gear. Simple registration of unit_inventory_changed and when it fires, get the toons name and populate a fontstring on a frame. My question is as long as the frame is open does a variable stay populated or saved?
if i have a variable peopleChangingGear and each time unit_inventory_changed fires I add that person's name to the variable. e.g.
peopleChangingGear = peopleChangingGear .. newNiinjaName
fontString:SetText(peopleChangingGear)
How long does peopleChangingGear stay populated? forever? until the frame is closed? on UI reload?I can't really answer that question without seeing the code, and even then I don't think that will be useful. If you create a table and store data into it then the data will remain in that table until the user interface is reloaded. It doesn't have anything to do with the frame being open or closed, but if you re-set it at any point to some base value (like "") then it would appear to be reset.
-
Posted by Taborious on Mon, 06 Apr 2009 13:14:13
Im using an array in my addon and after the window is closed I want to clear the entire array. In the _Close() function i tried just putting "arrayName = {}" but apparently that does not clear the array. How do I clear an array, do i have to parse through each element?
-
Posted by jnwhiteh on Mon, 06 Apr 2009 18:14:18
arrayName = {} leaves the original table intact, just changes the binding for the name 'arrayName' to a NEW table. If you want to clear a table, you can do it manually with:
for k,v in pairs(tbl) do
tbl[k] = nil
endAlternatively, you can call the Blizz defined function wipe() which does this for you, i.e. wipe(arrayName).
-
Posted by Taborious on Tue, 07 Apr 2009 08:16:14
TY! wipe(arrayName) seems much simpliar than a loop, any drawbacks?
-
Posted by Taborious on Tue, 07 Apr 2009 08:17:34
Before i saw your post I actually used setglobal("arrayName", nil) is that not good practice or not doing what i think it is? I'll change ti wipe() but just curious.
-
Posted by jnwhiteh on Tue, 07 Apr 2009 11:03:42
You should definitely not do it that way. setglobal() and getglobal() really shouldn't be used. You can just directly set it.