Thread Tools Display Modes
02-28-13, 08:50 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
How use tags saved in savedVariable?

I'm currently writing an ingame config for oUF_Diablo.

I set up 2 dropdown menus a user can choose tags from.

Lua Code:
  1. --health tag list for dropdown
  2.   db.list.health_tag = {
  3.     { value = "[diablo:healthorbtop]",  key = "oUF_Diablo top default", },
  4.     { value = "[diablo:healthorbbottom]",  key = "oUF_Diablo bottom default", },
  5.     { value = "[perhp]",  key = "Health Percent", },
  6.     { value = "[perhp]%",  key = "Health percent + %", },
  7.     { value = "[curhp]",  key = "Current health", },
  8.     { value = "[diablo:curhpshort]",  key = "Current health short", },
  9.     { value = "[maxhp]",  key = "Max health", },
  10.     { value = "[diablo:maxhpshort]",  key = "Max health short", },
  11.     { value = "[curhp]/[maxhp]",  key = "Current/Max health", },
  12.     { value = "[diablo:curhpshort]/[diablo:maxhpshort]",  key = "Current/Max health short", },
  13.     { value = "[diablo:empty]",  key = "Empty", },
  14.   }
  15.   db.getListHealthTag = function() return db.list.health_tag end
  16.  
  17.   ---------------------------------------------
  18.   --LIST / POWER TAGs
  19.   ---------------------------------------------
  20.  
  21.   --power tag list for dropdown
  22.   db.list.power_tag = {
  23.     { value = "[diablo:powerorbtop]",  key = "oUF_Diablo top default", },
  24.     { value = "[diablo:powerorbbottom]",  key = "oUF_Diablo bottom default", },
  25.     { value = "[perpp]",  key = "Power Percent", },
  26.     { value = "[perpp]%",  key = "Power percent + %", },
  27.     { value = "[curpp]",  key = "Current power", },
  28.     { value = "[diablo:curppshort]",  key = "Current power short", },
  29.     { value = "[maxpp]",  key = "Max power", },
  30.     { value = "[diablo:maxppshort]",  key = "Max power short", },
  31.     { value = "[curpp]/[maxpp]",  key = "Current/Max power", },
  32.     { value = "[diablo:curppshort]/[diablo:maxppshort]",  key = "Current/Max power short", },
  33.     { value = "[diablo:empty]",  key = "Empty", },
  34.   }
  35.   db.getListPowerTag = function() return db.list.power_tag end

Currently I initiate my unitframes right on code execution.

I add the tag via:
Code:
self:Tag(fontString, tagName)
The problem that occured is the following.

I cannot "reset" the tag later on (on "VARIABLES_LOADED" event) to another tag. Or atleast I do not know how. Because I tried and it did not work.

Basically I initialize my unitframe with a default tag and rewrite it later if the savedVariables are loaded to the database values. Well that is my plan that I fail to succeed.

How do you handle unit tag initilization, especially with tags only available later on?

Actually I did not plan to suppress unit initilization until the database is loaded. Currently I run it with default values and have view functions that update stuff later on when needed.

Can I not add a tag on unitframe init and just add it once on VARIABLES_LOADED? That would be enough for my needs.

*edit*


Hmm...I think I have an idea. Why should I change the tag if I can change how the tag function reacts.

This may work out:
Lua Code:
  1. ---------------------------------------------
  2.  
  3.   --HealthOrbTop
  4.   oUF.Tags.Methods["diablo:HealthOrbTop"] = function(unit)
  5.     local methodName = db.char["HEALTH"].value.top.tag
  6.     return oUF.Tags.Methods[methodName](unit) or ""
  7.   end
  8.   oUF.Tags.Events["diablo:HealthOrbTop"] = "UNIT_HEALTH UNIT_MAXHEALTH UNIT_CONNECTION"
  9.  
  10.   ---------------------------------------------
  11.  
  12.   --HealthOrbBottom
  13.   oUF.Tags.Methods["diablo:HealthOrbBottom"] = function(unit)
  14.     local methodName = db.char["HEALTH"].value.bottom.tag
  15.     return oUF.Tags.Methods[methodName](unit) or ""
  16.   end
  17.   oUF.Tags.Events["diablo:HealthOrbBottom"] = "UNIT_HEALTH UNIT_MAXHEALTH UNIT_CONNECTION"
  18.  
  19.   ---------------------------------------------
  20.  
  21.   --PowerOrbTop
  22.   oUF.Tags.Methods["diablo:PowerOrbTop"] = function(unit)
  23.     local methodName = db.char["POWER"].value.top.tag
  24.     return oUF.Tags.Methods[methodName](unit) or ""
  25.   end
  26.   oUF.Tags.Events["diablo:PowerOrbTop"] = "UNIT_DISPLAYPOWER UNIT_POWER UNIT_MAXPOWER UNIT_CONNECTION"
  27.  
  28.  
  29.   ---------------------------------------------
  30.  
  31.   --PowerOrbBottom
  32.   oUF.Tags.Methods["diablo:PowerOrbBottom"] = function(unit)
  33.     local methodName = db.char["POWER"].value.bottom.tag
  34.     return oUF.Tags.Methods[methodName](unit) or ""
  35.   end
  36.   oUF.Tags.Events["diablo:PowerOrbBottom"] = "UNIT_DISPLAYPOWER UNIT_POWER UNIT_MAXPOWER UNIT_CONNECTION"
  37.  
  38.   ---------------------------------------------

Basically on my orbs I have 2 value strings each. Thus I run 4 tags. Each of those tags can be set to any methodName. The choosen method is then loaded on tag update by itself.

Going to test it later.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-28-13 at 10:37 AM.
  Reply With Quote
02-28-13, 10:33 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
You should be using ADDON_LOADED and watching for your AddOn, as VARIABLES_LOADED is non-AddOn-specific.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
02-28-13, 03:38 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, in addition to oUF's self:Tag(fontstring, tag) method, there is also a self:Untag(fontstring) method, so if you can't wait until your saved variables are loaded to initialize your frames, just untag the fontstring and re-tag it with the saved info.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-01-13, 03:33 PM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Thanks Phanx. I tried Untagging. Didn't work for me. The idea I had worked out though.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
03-01-13, 05:12 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If Untag doesn't work, you should probably report it to Haste so he can fix it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How use tags saved in savedVariable?


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