An element of a custom GUI. This type is used to represent any kind of a GUI element - labels, buttons and 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 column_count of a textfield) will result in a runtime error.
For information on all supported GUI elements, see GuiElementType.
Each GUI element allows access to its children by having them as attributes. Thus, one can use the 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.
uint32unknownfalseThe index of this GUI element (unique amongst the GUI elements of a LuaPlayer).
LuaGuiunknownfalseThe GUI this element is a child of.
LuaGuiElementunknowntrueThe direct parent of this element. nil if this is a top-level element.
stringstringfalseThe name of this element. "" if no name was set.
LocalisedStringLocalisedStringfalseThe text displayed on this element. For frames, this is the "heading". For other elements, like buttons or labels, this is the content.
Whilst this attribute may be used on all elements without producing an error, it doesn't make sense for tables and flows as they won't display it.
doubledoublefalseHow much this progress bar is filled. It is a value in the range [0, 1].
GuiDirectionunknownfalseDirection of this element's layout.
LuaStyle | stringLuaStyle | stringfalseThe style of this element. When read, this evaluates to a LuaStyle. For writing, it only accepts a string that specifies the textual identifier (prototype name) of the desired style.
booleanbooleanfalseSets whether this GUI element is visible or completely hidden, taking no space in the layout.
stringstringfalseThe text contained in this textfield or text-box.
Array<string>unknownfalseNames 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.
booleanbooleanfalseIs this checkbox or radiobutton checked?
uint32unknownfalseIndex into LuaGameScript::players specifying the player who owns this element.
SpritePathSpritePathfalseThe sprite to display on this sprite-button or sprite in the default state.
booleanbooleanfalseWhether the sprite widget should resize according to the sprite in it. Defaults to true.
SpritePathSpritePathfalseThe sprite to display on this sprite-button when it is hovered.
SpritePathSpritePathfalseThe sprite to display on this sprite-button when it is clicked.
LocalisedStringLocalisedStringfalseThe text to display when hovering over this element. Writing "" or nil will disable the tooltip.
ElemIDElemIDtrueThe element tooltip to display when hovering over this element, or nil.
ScrollPolicyScrollPolicyfalsePolicy of the horizontal scroll bar.
ScrollPolicyScrollPolicyfalsePolicy of the vertical scroll bar.
GuiElementTypeunknownfalseThe type of this GUI element.
Array<LuaGuiElement>unknownfalseThe child-elements of this GUI element.
Array<LocalisedString>Array<LocalisedString>falseThe items in this dropdown or listbox.
uint32uint32falseThe selected index for this dropdown or listbox. Returns 0 if none is selected.
LuaQualityPrototypeQualityIDtrueThe quality to be shown in the bottom left corner of this sprite-button, or nil to show nothing.
doubledoubletrueThe number to be shown in the bottom right corner of this sprite-button, or nil to show nothing.
booleanbooleanfalseRelated to the number to be shown in the bottom right corner of this sprite-button. When set to true, numbers that are non-zero and smaller than one are shown as a percentage rather than the value. For example, 0.5 will be shown as 50% instead.
GuiLocationGuiLocationtrueThe location of this widget when stored in LuaGui::screen. nil if not set or not in LuaGui::screen.
booleanbooleanfalseWhether this frame auto-centers on window resize when stored in LuaGui::screen.
LocalisedStringLocalisedStringfalseThe text to display after the normal tab text (designed to work with numbers)
booleanbooleanfalseWhether this button will automatically toggle when clicked.
booleanbooleanfalseWhether this button is currently toggled. When a button is toggled, it will use the selected_graphical_set and selected_font_color defined in its style.
defines.game_controller_interactiondefines.game_controller_interactionfalseHow this element should interact with game controllers.
MapPositionMapPositionfalseThe position this camera or minimap is focused on, if any.
uint32uint32falseThe surface index this camera or minimap is using.
doubledoublefalseThe zoom this camera or minimap is using. This value must be positive.
uint32uint32falseThe player index this minimap is using.
stringstringtrueThe force this minimap is using, if any.
ElemTypeunknownfalseThe elem type of this choose-elem-button.
string | SignalID | PrototypeWithQualitystring | SignalID | PrototypeWithQualitytrueThe elem value of this choose-elem-button, if any.
The "signal" type operates with SignalID.
The "with-quality" types operate with PrototypeWithQuality.
The remaining types use strings.
PrototypeFilterPrototypeFiltertrueThe elem filters of this choose-elem-button, if any. The compatible type of filter is determined by elem_type.
Writing to this field does not change or clear the currently selected element.
booleanbooleanfalseWhether the contents of this text-box are selectable. Defaults to true.
booleanbooleanfalseWhether this text-box will word-wrap automatically. Defaults to false.
booleanbooleanfalseWhether this text-box is read-only. Defaults to false.
booleanbooleanfalseWhether this GUI element is enabled. Disabled GUI elements don't trigger events when clicked.
booleanbooleanfalseWhether this GUI element is ignored by interaction. This makes clicks on this element 'go through' to the GUI element or even the game surface below it.
booleanbooleanfalseWhether this choose-elem-button can be changed by the player.
booleanbooleanfalseWhether this table should draw vertical grid lines.
booleanbooleanfalseWhether this table should draw horizontal grid lines.
booleanbooleanfalseWhether this table should draw a horizontal grid line below the first table row.
uint32unknownfalseThe number of columns in this table.
booleanbooleanfalseWhether the content of this table should be vertically centered. Overrides LuaStyle::column_alignments. Defaults to true.
doubledoublefalseThe value of this slider element.
MouseButtonFlagsMouseButtonFlagsfalseThe mouse button filters for this button or sprite-button.
booleanbooleanfalseWhether this textfield is limited to only numeric characters.
booleanbooleanfalseWhether this textfield (when in numeric mode) allows decimal numbers.
booleanbooleanfalseWhether this textfield (when in numeric mode) allows negative numbers.
booleanbooleanfalseWhether this textfield displays as a password field, which renders all characters as *.
booleanbooleanfalseWhether this textfield loses focus after defines.events.on_gui_confirmed is fired.
booleanunknownfalseWhether this textfield or text-box was created with an icon selector.
LuaGuiElementLuaGuiElementtrueThe frame that is being moved when dragging this GUI element, if any. This element needs to be a child of the drag_target at some level.
Only top-level elements in LuaGui::screen can be drag_targets.
uint32uint32trueThe selected tab index for this tabbed pane, if any.
Array<TabAndContent>unknownfalseThe tabs and contents being shown in this tabbed-pane.
LuaEntityLuaEntitytrueThe entity associated with this entity-preview, camera, minimap, if any.
GuiAnchorGuiAnchortrueThe anchor for this relative widget, if any. Setting nil clears the anchor.
TagsTagsfalseThe tags associated with this LuaGuiElement.
booleanbooleanfalseWhether this element will raise on_gui_hover and on_gui_leave.
SwitchStateSwitchStatefalseThe switch state for this switch.
If LuaGuiElement::allow_none_state is false this can't be set to "none".
booleanbooleanfalseWhether the "none" state is allowed for this switch.
This can't be set to false if the current switch_state is 'none'.
LocalisedStringLocalisedStringfalseThe text shown for the left switch label.
LocalisedStringLocalisedStringfalseThe tooltip shown on the left switch label.
LocalisedStringLocalisedStringfalseThe text shown for the right switch label.
LocalisedStringLocalisedStringfalseThe tooltip shown on the right switch label.
booleanunknownfalseIs this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.
stringunknownfalseThe class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
LuaGuiElement.add{ type: GuiElementType, name?: string, caption?: LocalisedString, tooltip?: LocalisedString, elem_tooltip?: ElemID, enabled?: boolean, visible?: boolean, locked?: boolean, ignored_by_interaction?: boolean, style?: string, tags?: Tags, index?: uint32, anchor?: GuiAnchor, game_controller_interaction?: defines.game_controller_interaction, raise_hover_events?: boolean } -> LuaGuiElement
guiElement.add{ type=type }
takes_table: truetable_optional: falseAdd a new child element to this GuiElement.
type: GuiElementType — The kind of element to add, which potentially has its own attributes as listed below.name?: string — Name of the child element. It must be unique within the parent element.caption?: LocalisedString — Text displayed on the child element. For frames, this is their title. For other elements, like buttons or labels, this is the content. Whilst this attribute may be used on all elements, it doesn't make sense for tables and flows as they won't display it.tooltip?: LocalisedString — Tooltip of the child element.elem_tooltip?: ElemID — Elem tooltip of the child element. Will be displayed above tooltip.enabled?: boolean — Whether the child element is enabled. Defaults to true.visible?: boolean — Whether the child element is visible. Defaults to true.locked?: boolean — Whether the child element is locked. Defaults to false.ignored_by_interaction?: boolean — Whether the child element is ignored by interaction. Defaults to false.style?: string — The name of the style prototype to apply to the new element.tags?: Tags — Tags associated with the child element.index?: uint32 — Location in its parent that the child element should slot into. By default, the child will be appended onto the end.anchor?: GuiAnchor — Where to position the child element when in the relative element.game_controller_interaction?: defines.game_controller_interaction — How the element should interact with game controllers. Defaults to defines.game_controller_interaction.normal.raise_hover_events?: boolean — Whether this element will raise on_gui_hover and on_gui_leave. Defaults to false.LuaGuiElement — The GUI element that was added.LuaGuiElement.clear()
guiElement.clear()
takes_table: falsetable_optional: falseRemove children of this element. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
LuaGuiElement.destroy()
guiElement.destroy()
takes_table: falsetable_optional: falseRemove this element, along with its children. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
The top-level GUI elements - LuaGui::top, LuaGui::left, LuaGui::center and LuaGui::screen - can't be destroyed.
LuaGuiElement.get_mod() -> string?
guiElement.get_mod()
takes_table: falsetable_optional: falseThe mod that owns this Gui element or nil if it's owned by the scenario script.
This has a not-super-expensive, but non-free cost to get.
string?LuaGuiElement.get_index_in_parent() -> uint32
guiElement.get_index_in_parent()
takes_table: falsetable_optional: falseGets the index that this element has in its parent element.
This iterates through the children of the parent of this element, meaning this has a non-free cost to get, but is faster than doing the equivalent in Lua.
uint32LuaGuiElement.swap_children(index_1: uint32, index_2: uint32)
guiElement.swap_children(index_1, index_2)
takes_table: falsetable_optional: falseSwaps the children at the given indices in this element.
index_1: uint32 — The index of the first child.index_2: uint32 — The index of the second child.LuaGuiElement.clear_items()
guiElement.clear_items()
takes_table: falsetable_optional: falseRemoves the items in this dropdown or listbox.
LuaGuiElement.get_item(index: uint32) -> LocalisedString
guiElement.get_item(index)
takes_table: falsetable_optional: falseGets the item at the given index from this dropdown or listbox.
index: uint32 — The index to getLocalisedStringLuaGuiElement.set_item(index: uint32, string: LocalisedString)
guiElement.set_item(index, string)
takes_table: falsetable_optional: falseSets the given string at the given index in this dropdown or listbox.
index: uint32 — The index whose text to replace.string: LocalisedString — The text to set at the given index.LuaGuiElement.add_item(string: LocalisedString, index?: uint32)
guiElement.add_item(string, index)
takes_table: falsetable_optional: falseInserts a string at the end or at the given index of this dropdown or listbox.
string: LocalisedString — The text to insert.index?: uint32 — The index at which to insert the item.LuaGuiElement.remove_item(index: uint32)
guiElement.remove_item(index)
takes_table: falsetable_optional: falseRemoves the item at the given index from this dropdown or listbox.
index: uint32 — The indexLuaGuiElement.get_slider_minimum() -> double
guiElement.get_slider_minimum()
takes_table: falsetable_optional: falseGets this sliders minimum value.
doubleLuaGuiElement.get_slider_maximum() -> double
guiElement.get_slider_maximum()
takes_table: falsetable_optional: falseGets this sliders maximum value.
doubleLuaGuiElement.set_slider_minimum_maximum(minimum: double, maximum: double)
guiElement.set_slider_minimum_maximum(minimum, maximum)
takes_table: falsetable_optional: falseSets this sliders minimum and maximum values. The minimum can't be >= the maximum.
minimum: doublemaximum: doubleLuaGuiElement.get_slider_value_step() -> double
guiElement.get_slider_value_step()
takes_table: falsetable_optional: falseGets the minimum distance this slider can move.
doubleLuaGuiElement.get_slider_discrete_values() -> boolean
guiElement.get_slider_discrete_values()
takes_table: falsetable_optional: falseReturns whether this slider only allows discrete values.
booleanLuaGuiElement.set_slider_value_step(value: double)
guiElement.set_slider_value_step(value)
takes_table: falsetable_optional: falseSets the minimum distance this slider can move. The minimum distance can't be > (max - min).
value: doubleLuaGuiElement.set_slider_discrete_values(value: boolean)
guiElement.set_slider_discrete_values(true)
takes_table: falsetable_optional: falseSets whether this slider only allows discrete values.
value: booleanLuaGuiElement.focus()
guiElement.focus()
takes_table: falsetable_optional: falseFocuses this GUI element if possible.
LuaGuiElement.scroll_to_top()
guiElement.scroll_to_top()
takes_table: falsetable_optional: falseScrolls this scroll bar to the top.
LuaGuiElement.scroll_to_bottom()
guiElement.scroll_to_bottom()
takes_table: falsetable_optional: falseScrolls this scroll bar to the bottom.
LuaGuiElement.scroll_to_left()
guiElement.scroll_to_left()
takes_table: falsetable_optional: falseScrolls this scroll bar to the left.
LuaGuiElement.scroll_to_right()
guiElement.scroll_to_right()
takes_table: falsetable_optional: falseScrolls this scroll bar to the right.
LuaGuiElement.scroll_to_element(element: LuaGuiElement, scroll_mode?: "in-view" | "top-third")
guiElement.scroll_to_element(element, scroll_mode)
takes_table: falsetable_optional: falseScrolls this scroll bar such that the specified GUI element is visible to the player.
element: LuaGuiElement — The element to scroll to.scroll_mode?: "in-view" | "top-third" — Where the element should be positioned in the scroll-pane. Defaults to "in-view".LuaGuiElement.select_all()
guiElement.select_all()
takes_table: falsetable_optional: falseSelects all the text in this textbox.
LuaGuiElement.select(start_index: int32, end_index: int32)
guiElement.select(start_index, end_index)
takes_table: falsetable_optional: falseSelects a range of text in this textbox.
start_index: int32 — The index of the first character to selectend_index: int32 — The index of the last character to selectLuaGuiElement.add_tab(tab: LuaGuiElement, content: LuaGuiElement)
guiElement.add_tab(tab, content)
takes_table: falsetable_optional: falseAdds the given tab and content widgets to this tabbed pane as a new tab.
tab: LuaGuiElement — The tab to add, must be a GUI element of type "tab".content: LuaGuiElement — The content to show when this tab is selected. Can be any type of GUI element.LuaGuiElement.remove_tab(tab?: LuaGuiElement)
guiElement.remove_tab()
takes_table: falsetable_optional: falseRemoves the given tab and its associated content from this tabbed pane.
Removing a tab does not destroy the tab or the tab contents. It just removes them from the view.
tab?: LuaGuiElement — The tab to remove or nil to remove all tabs.LuaGuiElement.force_auto_center()
guiElement.force_auto_center()
takes_table: falsetable_optional: falseForces this frame to re-auto-center. Only works on frames stored directly in LuaGui::screen.
LuaGuiElement.scroll_to_item(index: int32, scroll_mode?: "in-view" | "top-third")
guiElement.scroll_to_item(index, scroll_mode)
takes_table: falsetable_optional: falseScrolls the scroll bar such that the specified listbox item is visible to the player.
index: int32 — The item index to scroll to.scroll_mode?: "in-view" | "top-third" — Where the item should be positioned in the list-box. Defaults to "in-view".LuaGuiElement.bring_to_front()
guiElement.bring_to_front()
takes_table: falsetable_optional: falseMoves this GUI element to the "front" so it will draw over other elements.
Only works for elements in LuaGui::screen.
LuaGuiElement.close_dropdown()
guiElement.close_dropdown()
takes_table: falsetable_optional: falseCloses the dropdown list if this is a dropdown and it is open.