From bc755344972d55f6596780afc36ce71d1f2de5e8 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 28 Jun 2015 10:39:02 +0700 Subject: [PATCH] Correct inaccuracy regarding node meta formspecs. --- chapters/formspecs.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/chapters/formspecs.md b/chapters/formspecs.md index fab5313..23113a8 100644 --- a/chapters/formspecs.md +++ b/chapters/formspecs.md @@ -254,14 +254,24 @@ minetest.register_node("mymod:rightclick", { local meta = minetest.get_meta(pos) meta:set_string("formspec", - "size[3,2]".. - "label[1,1;This is shown on right click]") - end + "size[5,5]".. + "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 }) {% endhighlight %} -Formspecs set this way do not trigger callbacks. -This method really only works for inventories. -Use on_rightclick and minetest.show_formspec if you want callbacks. +Formspecs set this way do not trigger the same callback. In order to +receive form input for meta formspecs, you must include an +`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*