Correct inaccuracy regarding node meta formspecs.

This commit is contained in:
Phil Hagelberg 2015-06-28 10:39:02 +07:00
parent fe44cf8448
commit bc75534497

View File

@ -254,14 +254,24 @@ minetest.register_node("mymod:rightclick", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", meta:set_string("formspec",
"size[3,2]".. "size[5,5]"..
"label[1,1;This is shown on right click]") "label[1,1;This is shown on right click]"..
"field[1,2;2,1;x;x;]")
end,
on_receive_fields = function(pos, formname, fields, player)
if(fields.quit) then return end
print(fields.x)
end end
}) })
{% endhighlight %} {% endhighlight %}
Formspecs set this way do not trigger callbacks. Formspecs set this way do not trigger the same callback. In order to
This method really only works for inventories. receive form input for meta formspecs, you must include an
Use on_rightclick and minetest.show_formspec if you want callbacks. `on_receive_fields` entry when registering the node.
This style of callback can trigger the callback when you press enter
in a field, which is impossible with `minetest.show_formspec`,
however, this kind of form can only be shown by right-clicking on a
node. It cannot be triggered programmatically.
*Note: node meta data will have been explained by this point in the full book* *Note: node meta data will have been explained by this point in the full book*