how do you (?update?) a formspec?

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

how do you (?update?) a formspec?

by tbillion » Sun Nov 29, 2015 12:36

say a user opens a formspec sets the data (custom integers and then closes it, how do you keep the user infromation stored or transfer it to another node, say the node destroys it self and moves itself. i know how to move the information just not how to update the form upon user exit or renetry/recreation.
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: how do you (?update?) a formspec?

by tbillion » Sun Nov 29, 2015 22:10

"default is the default value of the field. default may contain variable references such as ${text} which will fill the value from the metadata value text."
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: how do you (?update?) a formspec?

by rubenwardy » Sun Nov 29, 2015 23:42

If the value is related to the node, then you should store the value in meta like so:

Formspec is stored in meta:
Node Metadata
Node Metadata Formspecs

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 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.
Code: Select all
meta:set_string("value", "")


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)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 15 guests

cron