add{type=…, name=…, style=…} | Add a child element. |
destroy() | Remove this element, along with its children. |
gui :: LuaGui [R] | The GUI this element is a part of. |
parent :: LuaGuiElement [R] | The direct parent of this element; nil if this is a top-level element. |
name :: string [R] | The name of this element. |
caption :: string [RW] | The text displayed on the element. |
value :: double [RW] | How much this progress bar is filled. |
direction :: string [RW] | Direction of the layout. |
style :: LuaStyle or string [RW] | The style of this element. |
text :: string [RW] | The text contained in a textfield. |
children_names :: array of string [R] | Names of all the children of this element. |
state :: boolean [RW] | Is this checkbox checked? |
player_index :: uint [R] | Index into LuaGameScript::players specifying the player who owns this element. |
An element of the custom GUI. This type is used to represent any kind of a GUI element -- labels as well
as buttons as well as frames are all instances of this type. Just like LuaEntity, different kinds
of elements support different attributes; attempting to access an attribute on an element that doesn't support
it (for instance, trying to access the value
of a text field) will result in a run-time error.
The following kinds of GUI elements are supported:
"button"
: Clickable elements that fire on_gui_click when clicked."checkbox"
: Clickable elements with a cross in the mdidle that can be turned off or on. They also
fire on_gui_click when clicked."flow"
: Invisible containers that lay out children either horizontally or vertically. All three root
GUI elements (top
, left
and center
; see LuaGui) are flows."frame"
: Grey semi-transparent boxes that contain other elements. They have a caption, and, just
like flows, they lay out children either horizontally or vertically."label"
: A piece of text."progressbar"
: Indicate progress by displaying a partially filled bar."table"
: An invisible container that lays out children in a specific number of columns.
Colum width is given by the largest element contained in that row."textfield"
: Boxes of text the user can type in.parent.child
syntax to refer to children. Lua also supports the parent["child"]
syntax to refer to the
same element. This can be used in cases where the child has a name that isn't a valid Lua identifier.
greeting
to the top flow. Immediately after, it will change its text
to illustrate accessing child elements.
game.local_player.gui.top.add{type="label", name="greeting", caption="Hi"}
game.local_player.gui.top.greeting.caption = "Hello there!"
game.local_player.gui.top["greeting"].caption = "Actually, nevermind, I don't like your face"
Add a child element.
"button"
, "checkbox"
, "flow"
,
"frame"
, "label"
, "table"
, "progressbar"
, or "textfield"
.type
Remove this element, along with its children. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
game.local_player.gui.top.greeting.destroy()
The GUI this element is a part of.
The direct parent of this element; nil
if this is a top-level element.
The name of this element.
game.local_player.gui.top.greeting.name == "greeting"
How much this progress bar is filled. It is a value in range [0, 1].
Direction of the layout. May be either "horizontal"
or "vertical"
.
The style of this element. When read, this evaluates to a LuaStyle. For writing, it only accepts a string that specifies the textual identifier of the desired style.
The text contained in a textfield.
Names of all the children of this element. These are the identifiers that can be used to access the child as an attribute of this element.
Is this checkbox checked?
Index into LuaGameScript::players specifying the player who owns this element.