OAP Lizzard A game interface engine
Game interfaces, outside the game Settings
← XML guide

Documentation / XML guide

Scripts and load order

Script handlers, append and prepend, and when OnLoad and OnShow run.

Writing a handler

A handler can be written three ways:

<Scripts>
  <OnLoad method="OnLoad"/>                     <!-- self:OnLoad(), from a mixin -->
  <OnShow function="MyWindow_OnShow"/>          <!-- a global function -->
  <OnClick>
    print(self:GetName(), button, down)         -- a body
  </OnClick>
</Scripts>
  • method="OnLoad" calls self:OnLoad(...), usually a function from a mixin.
  • function="Name" calls a global function. If there is no such function when the frame is built, the handler is left out and Lizzard says so.
  • A body is Lua. It gets self, then names for the script's arguments, then ....

The argument names a body gets, from the names Blizzard's own bodies use:

ScriptArguments after self
OnClickbutton, down Measured (Retail)
OnDoubleClick, OnMouseDown, OnMouseUp, OnDragStartbutton
OnEnter, OnLeavemotion
OnEventevent, then the event's own values in ...
OnUpdateelapsed
OnSizeChangedwidth, height
OnValueChangedvalue, userInput Guessed order
OnTextChangeduserInput
OnKeyDown, OnKeyUpkey
OnMouseWheeldelta
OnVerticalScroll, OnHorizontalScrolloffset

A template's handler and your own

When a template already has a handler for a script, the element's own handler replaces it, unless it says inherit="append" or inherit="prepend". Then both run, in an order that reads the wrong way round:

<Frame name="MyPanelTemplate" virtual="true">
  <Scripts>
    <OnLoad>print("template")</OnLoad>
  </Scripts>
</Frame>

<Frame name="MyPanel" inherits="MyPanelTemplate">
  <Scripts>
    <OnLoad inherit="append">print("own")</OnLoad>
  </Scripts>
</Frame>
The order append and prepend run in With inherit="append", the element's own handler runs first and the template's second. With inherit="prepend", the template's runs first and the element's own second. With neither, only the element's own runs. inherit="append" 1 own: "own" 2 template: "template" inherit="prepend" 1 template: "template" 2 own: "own" neither own only template: replaced
"Append" puts your handler first. That is what the game does. Measured (Retail) Blizzard's chat edit box relies on it: its own append handler sets a value that its template's OnLoad then reads. Blizzard's code

When OnLoad runs

A frame's OnLoad doesn't run the moment the frame is made. Lizzard waits until the outermost frame being built is complete, every child and template included. Then OnLoad runs for each frame built, children before their parents.

The order OnLoad runs in for a window and its children A window holds a header and a footer, and the header holds an icon. OnLoad runs for the icon first, then the header, then the footer, and the window last. Then OnShow runs in the same order for those that are shown. MyWindow 4 Header 2 Footer 3 Icon 1 Each frame's OnLoad runs once it is complete: a child completes first. Then OnShow, same order, for shown frames.
By the time a parent's OnLoad runs, every child's OnLoad has run and every value from every template is in place. Blizzard's code needs it: the game menu's buttons read, in a child's OnLoad, a value their own template sets after that child is made.
  • After all the OnLoads, OnShow runs, in the same order, for each frame from XML that is shown. Measured (Retail) that it runs: the game's party frame makes its members in OnShow. Guessed the order.
  • CreateFrame in Lua applies the templates, then runs OnLoad the same way. It doesn't run OnShow. Guessed
  • In an intrinsic type's own element (intrinsic types), intrinsicOrder="postcall" runs that handler after the frame's own; otherwise it runs before.