Lua Table Formspec

From Minetest Developer Wiki
Jump to: navigation, search

Formspec

Formspec defines a menu. It is represented by a table in Lua. Note, this is not currently implemented and is apparently just a proposal.

Examples

  • Chest:
{"invsize", w=8, h=9}
{"list", inventorylocation="context", listname="main", x=0, y=0, w=8, h=4}
{"list", inventorylocation="current_player", listname="main", x=0, y=5, w=8, h=4}
  • Furnace:
{"invsize", w=8, h=9}
{"list", inventorylocation="context", listname="fuel", x=2, y=3, w=1, h=1}
{"list", inventorylocation="context", listname="src", x=2, y=1, w=1, h=1}
{"list", inventorylocation="context", listname="dest", x=5, y=1, w=2, h=2}
{"list", inventorylocation="current_player", listname="main", x=0, y=5, w=8, h=4}
  • Minecraft-like player inventory
{"invsize", w=8, h=7.5}
{"image", x=1, y=0.6, w=1, h=2, texturename="player.png"}
{"list", inventorylocation="current_player", listname="main", x=0, y=3.5, w=8, h=4}
{"list", inventorylocation="current_player", listname="craft", x=3, y=0, w=3, h=3}
{"list", inventorylocation="current_player", listname="craftpreview", x=7, y=1, w=1, h=1}

Elements

{"size", w=<Width>, h=<Height>}
Define the size of the menu in inventory slots
deprecated: {"invsize", w=<Width>, h=<Height>}
{"list", inventorylocation="<inventory location>", listname="<list name>", x=<X>, y=<Y>, w=<Width>, h=<Height>}
{"list", inventorylocation="<inventory location>", listname="<list name>", x=<X>, y=<Y>, w=<Width>, h=<Height>,
startingitemindex=<starting item index>}
Show an inventory list
{"image", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>"}
Show an image
Position and size units are inventory slots
{"item_image", x=<X>, y=<Y>, w=<Width>, h=<Height>, itemname="<item name>"}
Show an inventory image of registered item/node
Position and size units are inventory slots
{"background", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>"}
Use a background. Inventory rectangles are not drawn then.
Position and size units are inventory slots
Example for formspec 8x4 in 16x resolution: image shall be sized 8*16px x 4*16px
{"pwdfield", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", label="<label>"}
Textual password style field; will be sent to server when a button is clicked
x and y position the field relative to the top left of the menu
w and h are the size of the field
fields are a set height, but will be vertically centred on h
Position and size units are inventory slots
name is the name of the field as returned in fields to on_receive_fields
label, if not blank, will be text printed on the top left above the field
{"field", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", label="<label>", default="<default>"}
Textual field; will be sent to server when a button is clicked
x and y position the field relative to the top left of the menu
w and h are the size of the field
fields are a set height, but will be vertically centred on h
Position and size units are inventory slots
name is the name of the field as returned in fields to on_receive_fields
label, if not blank, will be text printed on the top left above the field
default is the default value of the field
default may contain variable references such as '${text}' which
will fill the value from the metadata value 'text'
note.png
Note: no extra text or more than a single variable is supported at the moment


{"field", name="<name>", label="<label>", default="<default>"}
as above but without position/size units
special field for creating simple forms, such as sign text input
must be used without a {"size"} element
a 'Proceed' button will be added automatically
{"textarea", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", label="<label>", default="<default>"}
same as fields above, but with multi-line input
{"label", x=<X>, y=<Y>, label="<label>"}
x and y work as per field
label is the text on the label
Position and size units are inventory slots
{"vertlabel", x=<X>, y=<Y>, label="<label>"}
Textual label drawn verticaly
x and y work as per field
label is the text on the label
Position and size units are inventory slots
{"button", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", label="<label>"}
Clickable button. When clicked, fields will be sent.
x, y and name work as per field
w and h are the size of the button
label is the text on the button
Position and size units are inventory slots
{"image_button", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>", name="<name>", label="<label>"}
x, y, w, h, and name work as per button
texture name is the filename of an image
Position and size units are inventory slots
{"image_button", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>", name="<name>", label="<label>",
noclip=<noclip>}
x, y, w, h, and name work as per button
texture name is the filename of an image
Position and size units are inventory slots
noclip true means imagebutton doesn't need to be within specified formsize
{"image_button", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>", name="<name>", label="<label>",
noclip=<noclip>, drawborder=<drawborder>}
x, y, w, h, and name work as per button
texture name is the filename of an image
Position and size units are inventory slots
noclip true means imagebutton doesn't need to be within specified formsize
drawborder draw button border or not
{"image_button", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>", name="<name>", label="<label>",
noclip=<noclip>, drawborder=<drawborder>, pressed="<texture name>"}
x, y, w, h, and name work as per button
texture name is the filename of an image
Position and size units are inventory slots
noclip true means imagebutton doesn't need to be within specified formsize
drawborder draw button border or not
pressed is the filename of an image on pressed state
{"item_image_button", x=<X>, y=<Y>, w=<Width>, h=<Height>, itemname="<item name>", name="<name>", label="<label>"}
x, y, w, h, name and label work as per button
item name is the registered name of an item/node,
tooltip will be made out of its description
Position and size units are inventory slots
{"button_exit", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", label="<label>"}
When clicked, fields will be sent and the form will quit.
{"image_button_exit", x=<X>, y=<Y>, w=<Width>, h=<Height>, texturename="<texture name>", name="<name>", label="<label>"}
When clicked, fields will be sent and the form will quit.
{"textlist", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", list=<array of string/number/boolean>}
Scrollable itemlist showing arbitrary text elements
x and y position the itemlist relative to the top left of the menu
w and h are the size of the itemlist
name fieldname sent to server on doubleclick value is current selected element
list elements can be a table with color, e.g. {"list element 1", {text="list element 2", color="ff0000"}, "list element 3"}
{"textlist", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", list=<array of string/number/boolean>,
transparent=<transparent>}
Scrollable itemlist showing arbitrary text elements
x and y position the itemlist relative to the top left of the menu
w and h are the size of the itemlist
name fieldname sent to server on doubleclick value is current selected element
list elements can be a table with color, e.g. {"list element 1", {text="list element 2", color="ff0000"}, "list element 3"}
draw transparent background
{"tabheader", x=<X>, y=<Y>, name="<name>", captions=<array of strings>, current_tab=<current_tab>,
transparent=<transparent>, drawborder=<drawborder>}
show a tabHEADER at specific position (ignores formsize)
x and y position the itemlist relative to the top left of the menu
name fieldname data is transferred to lua
captions specifies name shown on top of tab
current_tab index of selected tab
transparent (optional) show transparent
draw_border (optional) draw border
{"box", x=<X>, y=<Y>, w=<Width>, h=<Height>, color="<color>"}
simple colored semitransparent box
x and y position the box relative to the top left of the menu
w and h are the size of box
color in hexadecimal format RRGGBB
{"dropdown", x=<X>, y=<Y>, w=<Width>, name="<name>", items=<array of string/number/boolean>, index=<selected index>}
dropdown field
x and y position of dropdown
width of dropdown
fieldname data is transferred to lua
items to be shown in dropdown
index of currently selected dropdown item
{"checkbox", x=<X>, y=<Y>, name="<name>", label="<label>", selected=<selected>}
show a checkbox
x and y position of checkbox
name fieldname data is transferred to lua
label to be shown left of checkbox
selected (optional) true/false
note.png
Note: do NOT use a element name starting with "key_", those names are reserved to pass key press events to formspec!


Inventory location:

Retrieved from "http://dev.minetest.net/index.php?title=Lua_Table_Formspec&oldid=3190"
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox