Difference between revisions of "NodeMetaRef"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Redirected page to MetaDataRef)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The instance of a node in the world normally only contains the three values mentioned in "[[node|Nodes]]". However, it is possible to insert extra data into a
+
#REDIRECT [[MetaDataRef]]
node. It is called "node metadata".
 
 
 
Metadata contains two things:
 
* A key-value store
 
* An inventory
 
 
 
Some of the values in the key-value store are handled specially:
 
* <code>formspec</code> — Defines a right-click inventory menu. See "[[formspec|Formspec]]".
 
* <code>infotext</code> — Text shown on the screen when the node is pointed at
 
 
 
Can be gotten via <source enclose="none">minetest.env:get_meta(pos)</source>.
 
 
 
[[http://minetest.net/wiki/doku.php?id=code:storing_special_data_in_node_metadata Storing special data in node metadata]] - email question/reply in the old developer wiki (could be written in article form here)
 
 
 
== Methods ==
 
* <source enclose="none">set_string(name, value)</source>
 
* <source enclose="none">get_string(name)</source>
 
* <source enclose="none">set_int(name, value)</source>
 
* <source enclose="none">get_int(name)</source>
 
* <source enclose="none">set_float(name, value)</source>
 
* <source enclose="none">get_float(name)</source>
 
* <source enclose="none">[NodeMetaRef]get_inventory()</source> — returns [[InvRef]]
 
* <source enclose="none">[NodeMetaRef]to_table()</source> — returns <source enclose="none">nil</source> or <source enclose="none">{fields = {...}, inventory = {list1 = {}, ...}}</source>
 
* <source enclose="none">from_table(nil</source> or <source enclose="none">{})</source>
 
 
 
== Example ==
 
<source>
 
local meta = minetest.env:get_meta(pos)
 
meta:set_string("formspec",
 
        "invsize[8,9;]"..
 
        "list[context;main;0,0;8,4;]"..
 
        "list[current_player;main;0,5;8,4;]")
 
meta:set_string("infotext", "Chest");
 
local inv = meta:[NodeMetaRef]get_inventory()
 
inv:set_size("main", 8*4)
 
print(dump(meta:[NodeMetaRef]to_table()))
 
meta:from_table({
 
    inventory = {
 
        main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", [10] = "", [11] = "", [12] = "", [13] = "", [14] = "default:cobble", [15] = "", [16] = "", [17] = "", [18] = "", [19] = "", [20] = "default:cobble", [21] = "", [22] = "", [23] = "", [24] = "", [25] = "", [26] = "", [27] = "", [28] = "", [29] = "", [30] = "", [31] = "", [32] = ""}
 
    },
 
    fields = {
 
        formspec = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
 
        infotext = "Chest"
 
    }
 
})
 
</source>
 
 
 
[[Category:Objects]]
 

Latest revision as of 02:12, 7 March 2018

Redirect to: