GUIs (Formspecs): A few fixes + missing description
This commit is contained in:
parent
ec3a95cea6
commit
0b71965a6a
@ -3,6 +3,7 @@ title: GUIs (Formspecs)
|
|||||||
layout: default
|
layout: default
|
||||||
root: ../..
|
root: ../..
|
||||||
idx: 4.5
|
idx: 4.5
|
||||||
|
description: Learn how to display GUIs using formspecs
|
||||||
redirect_from: /en/chapters/formspecs.html
|
redirect_from: /en/chapters/formspecs.html
|
||||||
submit_vuln:
|
submit_vuln:
|
||||||
level: warning
|
level: warning
|
||||||
@ -74,9 +75,8 @@ on multiple lines, like so:
|
|||||||
|
|
||||||
Elements are items such as text boxes or buttons, or can be metadata such
|
Elements are items such as text boxes or buttons, or can be metadata such
|
||||||
as size or background. You should refer to
|
as size or background. You should refer to
|
||||||
[lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1019)
|
[lua_api.txt](../../lua_api.html#elements)
|
||||||
for a list of all possible elements. Search for "Formspec" to locate the correct
|
for a list of all possible elements.
|
||||||
part of the document.
|
|
||||||
|
|
||||||
|
|
||||||
### Header
|
### Header
|
||||||
@ -87,7 +87,7 @@ game-wide theme should be applied.
|
|||||||
|
|
||||||
The elements in the header must be defined in a specific order, otherwise you
|
The elements in the header must be defined in a specific order, otherwise you
|
||||||
will see an error. This order is given in the above paragraph, and, as always,
|
will see an error. This order is given in the above paragraph, and, as always,
|
||||||
documented in [lua_api.txt](../../lua_api.html#sizewhfixed_size)
|
documented in [lua_api.txt](../../lua_api.html#sizewhfixed_size).
|
||||||
|
|
||||||
The size is in formspec slots - a unit of measurement which is roughly
|
The size is in formspec slots - a unit of measurement which is roughly
|
||||||
around 64 pixels, but varies based on the screen density and scaling
|
around 64 pixels, but varies based on the screen density and scaling
|
||||||
@ -175,7 +175,7 @@ minetest.register_chatcommand("game", {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
The show_formspec function accepts a player name, the formspec name, and the
|
The `show_formspec` function accepts a player name, the formspec name, and the
|
||||||
formspec itself. The formspec name should be a valid itemname, ie: in the format
|
formspec itself. The formspec name should be a valid itemname, ie: in the format
|
||||||
`modname:itemname`.
|
`modname:itemname`.
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
The function given in minetest.register_on_player_receive_fields is called
|
The function given in `minetest.register_on_player_receive_fields` is called
|
||||||
every time a user submits a form. Most callbacks will need to check the formname given
|
every time a user submits a form. Most callbacks will need to check the formname given
|
||||||
to the function, and exit if it is not the right form; however, some callbacks
|
to the function, and exit if it is not the right form; however, some callbacks
|
||||||
may need to work on multiple forms, or on all forms.
|
may need to work on multiple forms, or on all forms.
|
||||||
@ -282,13 +282,13 @@ function guessing.get_formspec(name, context)
|
|||||||
elseif context.guess == context.target then
|
elseif context.guess == context.target then
|
||||||
text = "Hurray, you got it!"
|
text = "Hurray, you got it!"
|
||||||
elseif context.guess > context.target then
|
elseif context.guess > context.target then
|
||||||
text = "To high!"
|
text = "Too high!"
|
||||||
else
|
else
|
||||||
text = "To low!"
|
text = "Too low!"
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that it's good practice for get_formspec to only read the context, and not
|
Note that it's good practice for `get_formspec` to only read the context, and not
|
||||||
update it at all. This can make the function simpler, and also easier to test.
|
update it at all. This can make the function simpler, and also easier to test.
|
||||||
|
|
||||||
And finally, we need to update the handler to update the context with the guess:
|
And finally, we need to update the handler to update the context with the guess:
|
||||||
@ -307,17 +307,17 @@ end
|
|||||||
|
|
||||||
There are three different ways that a formspec can be delivered to the client:
|
There are three different ways that a formspec can be delivered to the client:
|
||||||
|
|
||||||
* [show_formspec](#guessing-game): the method used above, fields are received by register_on_player_receive_fields.
|
* [show_formspec](#guessing-game): the method used above, fields are received by `register_on_player_receive_fields`.
|
||||||
* [Node Meta Formspecs](#node-meta-formspecs): the node contains a formspec in its meta data, and the client
|
* [Node Meta Formspecs](#node-meta-formspecs): the node contains a formspec in its meta data, and the client
|
||||||
shows it *immediately* when the player rightclicks. Fields are received by a
|
shows it *immediately* when the player rightclicks. Fields are received by a
|
||||||
method in the node definition called `on_receive_fields`.
|
method in the node definition called `on_receive_fields`.
|
||||||
* [Player Inventory Formspecs](#player-inventory-formspecs): the formspec is sent to the client at some point, and then
|
* [Player Inventory Formspecs](#player-inventory-formspecs): the formspec is sent to the client at some point, and then
|
||||||
shown immediately when the player presses `i`. Fields are received by
|
shown immediately when the player presses `i`. Fields are received by
|
||||||
register_on_player_receive_fields.
|
`register_on_player_receive_fields`.
|
||||||
|
|
||||||
### Node Meta Formspecs
|
### Node Meta Formspecs
|
||||||
|
|
||||||
minetest.show_formspec is not the only way to show a formspec; you can also
|
`minetest.show_formspec` is not the only way to show a formspec; you can also
|
||||||
add formspecs to a [node's metadata](node_metadata.html). For example,
|
add formspecs to a [node's metadata](node_metadata.html). For example,
|
||||||
this is used with chests to allow for faster opening times -
|
this is used with chests to allow for faster opening times -
|
||||||
you don't need to wait for the server to send the player the chest formspec.
|
you don't need to wait for the server to send the player the chest formspec.
|
||||||
|
@ -3,6 +3,7 @@ title: Player Physics
|
|||||||
layout: default
|
layout: default
|
||||||
root: ../..
|
root: ../..
|
||||||
idx: 4.4
|
idx: 4.4
|
||||||
|
description: Learn how to make a player run faster, jump higher or simply float
|
||||||
redirect_from: /en/chapters/player_physics.html
|
redirect_from: /en/chapters/player_physics.html
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user