This page documents a user-defined function that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions

Call this function to wait a specified amount of time before running another function with the given parameters. This function is useful when you rely on system messages to trigger your code as (especially with Guild related system messages) the system message is dispatched by the server sometimes before the results have been updated. Waiting to perform the next step of your code becomes easy with this function.

<PREFIX>_wait(delay, func [, param [,param [,...]]])

Function Parameters[edit | edit source]

Arguments[edit | edit source]

Number - the amount of time to wait (in seconds) before the provided function is triggered
Function - The function to run once the wait delay is over.
any - A list of any additional parameters (of any assorted type) to pass to the provided function when it is triggered.

Returns[edit | edit source]

Boolean - true if it succeded in adding the wait to the wait table, If the first parameter is not a number, or the seconds parameter is not a function, any call to wait will automatically fail with a result of false.

NOTE: if the UIParent frame is being hidden, this wait will not work. It will never reach the end of the delay.

Example[edit | edit source]


Result[edit | edit source]

returns true after the initial call
after a 2.5 seconds delay, the string "Hello" will be displayed in the default chat frame.

Code[edit | edit source]

local waitTable = {};
local waitFrame = nil;

function <PREFIX>__wait(delay, func, ...)
  if(type(delay)~="number" or type(func)~="function") then
    return false;
  if(waitFrame == nil) then
    waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
    waitFrame:SetScript("onUpdate",function (self,elapse)
      local count = #waitTable;
      local i = 1;
      while(i<=count) do
        local waitRecord = tremove(waitTable,i);
        local d = tremove(waitRecord,1);
        local f = tremove(waitRecord,1);
        local p = tremove(waitRecord,1);
        if(d>elapse) then
          i = i + 1;
          count = count - 1;
  return true;
Community content is available under CC-BY-SA unless otherwise noted.