Working with Events

From Riftui Wiki

Revision as of 07:06, 5 July 2011 by Cairenn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

For an explanation of what an event is, see Event

Events in Rift are tables (see Table).

table.insert(Event.Addon.SavedVariables.Load.Begin, {Function, Identifier, Text Label})


Some Events may have additional, or even different parameters.

Example, from ZorbasBuffBars

local function refresh()
  -- Get the list of buffs from the player. Note that "player" can be replaced by "" to turn this into a target's-buff-bar display.
  local bufflist = Inspect.Buff.List("player")
  if not bufflist then return end -- If we don't get anything, then we don't currently have information about the player. This may happen when the player is logging in or teleporting long distances.
  local buffdetails = Inspect.Buff.Detail("player", bufflist) -- Retrieve the details for all of our buffs. If there were only certain buffs we cared about, we could filter them out before asking for detail.
  StartBuffBars() -- Reset the buff bars and start entering buffs.
  -- We want to order buffs by their time remaining, splitting apart buffs and debuffs. We do the ordering here, in standard Lua code.
  local bbars = {}
  for id, buff in pairs(buffdetails) do = id  -- Make a copy of the ID, because we'll need it
    table.insert(bbars, buff)
  table.sort(bbars, function (a, b)
    if a.buff ~= b.buff then
      return not b.buff
    if a.duration and b.duration then return a.remaining > b.remaining end
    if not a.duration and not b.duration then return false end
    return not a.duration
  -- Now that we have the ordering, we just add the bars one at a time. Done!
  for k, v in ipairs(bbars) do
-- Here's our event. As mentioned, this triggers every single frame. See TrionDevelopmentTools for more detail on events.
table.insert(Event.System.Update.Begin, {refresh, "ZorbasBuffBars", "refresh"})

You might notice a few things. The function refresh() is a local function, meaning it only exists and works in ZorbasBuffBars, and it is created before the Event that uses it, in this case Event.System.Update.Begin

table.insert is used to add the parameters to the Event. refresh is not a string, so it not in quotes, but you will also notice does not have () in the event. "ZorbasBuffBars" is a string, and is the Identifier in its toc file. "refresh" is a string, but in this case, it is not a very descriptive text label. It is fine for a simple addon, but with something much more complex, you would want to name it accordingly, like "buff_refresh_function" or the like.

Personal tools