If the value is related to the node, then you should store the value in meta like so:
Formspec is stored in meta:
Node MetadataNode Metadata FormspecsYour 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
local createNodeFormspec(value)
return "size[5,5]"..
"label[1,1;This is shown on right click]"..
"field[1,2;2,1;x;x;" .. value .. "]"
end
-- in the node definition:
after_place_node = function(pos, placer)
-- This function is run when the chest node is placed.
-- The following code sets the formspec for chest.
-- Meta is a way of storing data onto a node.
local meta = minetest.get_meta(pos)
if not meta then
return
end
meta:set_string("value", default_value)
meta:set_string("formspec", createNodeFormspec( meta:get_string("value") ))
end,
on_receive_fields = function(pos, formname, fields, player)
if(fields.quit) then
return
end
local meta = minetest.get_meta(pos)
if not meta then
return
end
meta:set_string("value", fields.x)
meta:set_string("formspec", createNodeFormspec( meta:get_string("value") ))
end
createNodeFormspec creates a formspec given some saved values - it's good to separate it like this to avoid duplication. default_value is some default value, you might for example use something like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
which is the same as
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
local default_value= ""
meta:set_string("value", default_value)