Page 1 of 1

getValueAt, a tool for configuration

Posted: Wed Jul 10, 2019 12:20 am
by demonnic
getValueAt(variableNameAsString)

This will return the same value as if you had read the variable itself. For instance, getValueAt("demonnic.chat.config.enabled") would be the same as referencing demonnic.chat.config.enabled directly

"Why do this?", I hear you asking.

I dunno how many other people may ever use this, but I was thinking recently about how to make some basic UI stuff scriptable, automated, and flexible. Such that you can tell it what stats you want to track and what variables to look in to track them. Like I do with YATCO for chat stuff, but leaving all the tracking of statistics and such to other packages/modules.

So, as a basic example, I want to run a gauge for something. I need their current value and max value. But I don't want to track that myself, a lot of people are already tracking that, and I'm trying to make something that can be easily layered on top of an existing setup without modifying it or double tracking. So instead, I'll ask where you keep those values.

Maybe an example is easiest.
Code: [show] | [select all] lua
-- let's just assume I instantiated all the tables earlier, ok?
demonnic.ui.statGauges = {"Health"}
demonnic.ui.stats[1].max = "gmcp.Char.Vitals.maxhp"
demonnic.ui.stats[1].current = "gmcp.Char.Vitals.hp"

--in the function I update gauges in later
for statNum,gaugeName in ipairs(demonnic.ui.statGauges) do
  local current = getValueAt(demonnic.ui.stats[statNum].current)
  local max = getValueAt(demonnic.ui.stats[statNum].max)
  demonnic.ui.updateStatValues(statNum, current, max)
end