WoW:XML/Script: Difference between revisions
Line 23: | Line 23: | ||
== Payload == | == Payload == | ||
* (optional) - Lua script as plain text called as a Lua function. | * (optional) - Lua script as plain text called as a Lua function. | ||
<pre> | |||
<Frame name="Frame1"> | |||
<Scripts> | |||
<OnMouseUp> | |||
print(self:GetName(), event, ...) -- payload | |||
</OnMouseUp> | |||
</Scripts> | |||
</Frame> | |||
<pre> | |||
=== Parameters === | === Parameters === | ||
Lua script parameters set by the engine for use by the inline script. | Lua script parameters set by the engine for use by the inline script. |
Revision as of 17:01, 16 January 2023
← XML UI ← XML properties < Script
Script is way to add handler code to a UI element. Script is base type that is not used directly, but added to <Scripts> using one of the specific handler types such as 'OnClick'. The Script type provides a base type for all of the hander types.
Inheritance
Inherited by: OnClick, OnEnter, OnLoad, OnEvent ..., Inherits: none, Defined in: Scripts, Runtime object: UIOBJECT_Script
Elements
- none
Attributes
- function (string) (optional)
- named function to call using a simple global name. Can be used instead of in payload with inline script text.
- method (string) (optional)
- named method to call using this frame's Lua table or 'mixin' name of function to call, in lieu of inline text or 'function'.
- inherit (SCRIPTINHERITTYPE) (optional)
- order to run this script relative to any other scripts for this event including any 'inherited'. Default is 'none'.
- intrinsicOrder (SCRIPTINTRINSICORDERTYPE) (optional)
- order to run this script relative to any implementation scripts for this event. Used only in an intrinsic definition. Default is 'none'.
- autoEnableInput (boolean) (optional)
- Unknown. Is set 'false' on a few mouse events for ScrollingMessageFrame and TextStatusBar and seems to have something to do with not activating text box under certain circumstances. Default is 'true'.
Payload
- (optional) - Lua script as plain text called as a Lua function.
<Frame name="Frame1">
<Scripts>
<OnMouseUp>
print(self:GetName(), event, ...) -- payload
</OnMouseUp>
</Scripts>
</Frame>
<pre>
=== Parameters ===
Lua script parameters set by the engine for use by the inline script.
* self - (table) the container table. For a Frame is the scripts Lua frame table itself
* event - (string) the name of the wow event
* ... - the remaining Lua args list including any event arguments
== Xsd ==
<pre>
<xs:complexType name="ScriptType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="function" type="xs:string"/>
<xs:attribute name="method" type="xs:string"/><!-- new after 7.1 -->
<xs:attribute name="inherit" type="SCRIPTINHERITTYPE" use="optional" default="none"/>
<xs:attribute name="intrinsicOrder" type="SCRIPTINTRINSICORDERTYPE" use="optional" default="none"/><!-- after 7.1 -->
<xs:attribute name="autoEnableInput" type="xs:boolean" default="true"/><!-- new after 7.2.5 -->
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Summary
Script based elements facilitate frame and other elements event handler mechanisms for the WoW UI at runtime. Allows WoW to run UI Lua code at runtime each frame and during startup. Without this general mechanism, only the global file-level Lua code during initial load would be able to run. So this is WoW's predominate way of calling into the Lua UI code form the regular client "C" code.
Example
<Frame name="MyFrameTemplate" hidden="true" virtual="true"/> <Frame name="MyFrame" inherts="MyFrameTemplate"> <Size x="400" y="400"/> <Frames> <Frame name="$parentChild" parentKey="child"> <Size x="200" y="100"/> <Scripts> <OnMouseUp> print(self:GetName(), "clicked", event, ...) </OnMouseUp> </Scripts> </Frame> </Frames> </Frame>
This example will align the top of the 'child' frame to the top of 'MyFrame', and print "clicked" on the chat window when the user's mouse button goes 'up' over the child frame.
See also
- XML/Scripts - for outer parent element
- XML_properties#Scripts - for a list of handlers
- Widget handlers - for which handlers work with which elements
- Category:Widget event handlers