Skip to content

Commit f630d2d

Browse files
committed
Formspecs: node meta and rephrasing
1 parent fd8c37a commit f630d2d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

chapters/formspecs.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tend to disrupt game play.
1919
* Displaying Forms
2020
* Callbacks
2121
* Contexts
22-
22+
* Node Meta Formspecs
2323

2424
Formspec Syntax
2525
---------------
@@ -179,3 +179,35 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
179179
end
180180
end)
181181
{% endhighlight %}
182+
183+
Node Meta Formspecs
184+
-------------------
185+
186+
minetest.show_formspec is not the only way to show a formspec, you can also
187+
add formspecs to a node's meta data. This is used on nodes such as chests to
188+
allow for faster opening times - you don't need to wait for the server to send
189+
the player the chest formspec.
190+
191+
{% highlight lua %}
192+
minetest.register_node("mymod:rightclick", {
193+
description = "Rightclick me!",
194+
tiles = {"mymod_rightclick.png"},
195+
groups = {cracky = 1},
196+
after_place_node = function(pos, placer)
197+
-- This function is run when the chest node is placed.
198+
-- The following code sets the formspec for chest.
199+
-- Meta is a way of storing data onto a node.
200+
201+
local meta = minetest.get_meta(pos)
202+
meta:set_string("formspec",
203+
"size[3,2]"..
204+
"label[1,1;This is shown on right click]")
205+
end
206+
})
207+
{% endhighlight %}
208+
209+
Formspecs set this way do not trigger callbacks.
210+
This method really only works for inventories.
211+
Use on_rightclick and minetest.show_formspec if you want callbacks.
212+
213+
*Note: node meta data will have been explained by this point in the full book*

0 commit comments

Comments
 (0)