Merge pull request #20 from technomancy/node-meta-formspec-correction

Correct inaccuracy regarding node meta formspecs.
master
rubenwardy 2015-06-28 12:29:53 +01:00
commit 72da76a506
1 changed files with 16 additions and 6 deletions

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]"..
end "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
}) })
{% 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*