The formspec is stored in the node metadata, which means it has to be set whenever the node is placed. This can be done from the node's
on_construct or
after_place_node callbacks. Use the former if you just care about any time the node is created, and use the latter if you only want to do it when a player specifically places the node from inventory. To set the actual formspec, you'll use code like:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_node(
...,
{
...,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", myFormspecString)
end,
...
})
As for the formspec string itself, currently the documentation in the lua_api.txt file that comes with the game is probably a little more complete and easy to understand than the stuff in the developer wiki. I've been meaning to synchronize the two a bit but haven't gotten to it yet. Pay particular attention to where there are semicolons (;) because it is very picky about those. If there is an extra one at the end of a command that doesn't need one, the formspec won't show, and if there is one missing in a command which is supposed to have one at the end, the formspec won't show. Also, just ignore anything that seems to imply you should use "context" for the node's inventory list; it must be "current_name" instead, or the formspec will not show.
Hope that helps and is a good start to exploring things. This functionality is a little finicky, but it shouldn't be too hard to get a very simple working prototype and expand little by little from there.