Can`t set inventory list with own name.

Post Reply
User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Can`t set inventory list with own name.

by Andrey01 » Post

I don`t know exactly how to do it. At fisrt i created formspec string that is:

Code: Select all

local name = minetest.get_node(pos).name
            local img_button1 = "image_button[0.5, 0;1, 2;" .. cab_boxes[1].img_button ..";" .. cab_boxes[1].button .. ";]"
            local img_button2 = "image_button[0.5, 3;1, 2;" .. cab_boxes[2].img_button .. ";" .. cab_boxes[2].button .. ";]"
            local list1 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[1].listname .. ";1.5, 0;4, 2]" -- The list name is 'kwc1_1'
            local list2 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[2].listname .. ";1.5, 1;4, 2]"  -- The list name is 'kwc2_1'                                                         
            form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2 .. "]"
            --minetest.debug(dump(cabinets))
            cabinets.put_data_into_cabinet(pos, "kitchen_wooden_cabinet", tostring(cabinet_num), cab_boxes, {name=name, data=form})
            local inv = minetest.get_inventory({type="node", pos=pos})
Then defined items amount in this list and its size:

Code: Select all

inv:set_list(cab_boxes[1].listname, cab_boxes[1].inv_list)
            inv:set_list(cab_boxes[2].listname, cab_boxes[2].inv_list)
            inv:set_size(cab_boxes[1].listname, cab_boxes[1].inv_size or 0)
            inv:set_size(cab_boxes[2].listname, cab_boxes[2].inv_size or 0)
It causes a warning:

Code: Select all

WARNING[Main]: GUIFormSpecMenu::drawList(): The inventory list "kwc1_1" @ "nodemeta:-192,3,-189" doesn't exist
WARNING[Main]: GUIFormSpecMenu::drawList(): The inventory list "kwc1_2" @ "nodemeta:-192,3,-189" doesn't exist
How do i need to create correctly inventory list with other name?

User avatar
AiTechEye
Member
Posts: 1000
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: Sweden

Re: Can`t set inventory list with own name.

by AiTechEye » Post

did you created the meta inventories too?

i mean

Code: Select all

after_place_node = function(pos, placer)
  local meta = minetest.get_meta(pos)
  meta:get_inventory():set_size("kwc1_1", 1)
  meta:get_inventory():set_size("kwc2_1", 1)
...

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Can`t set inventory list with own name.

by Andrey01 » Post

Yes... as i remember it was in on_construct callback. I`ll precise that, though when i will have a spare time.

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Can`t set inventory list with own name.

by Andrey01 » Post

I looked at my code today and i`m sure the inventories should be set (set up inventory names in formspec strings correctly, then set up size of each inventory), but it writes the same warning as in the first post.
My whole code:

Code: Select all

kit_wood_cabs = {
    ["kitchen_wooden_cabinet_1"] = {
        --form_size="",
        {mode="closed", button = "kwc1_1", img_button = "close_button.png", listname = "kwc1_1", inv_list={}, inv_size=0},
        {mode="closed", button = "kwc1_2", img_button = "close_button.png", listname = "kwc1_2", inv_list={}, inv_size=0}
        
    },
    ["kitchen_wooden_cabinet_2"] = {
        --form_size="",
        {mode="opened", button = "kwc2_1", img_button = "open_button.png", listname = "kwc2_1", inv_list={}, inv_size=4*2},
        {mode="closed", button = "kwc2_2", img_button = "close_button.png", listname = "kwc2_2", inv_list={}, inv_size=0},
        not_in_creative_inventory=1
        
    },
    ["kitchen_wooden_cabinet_3"] = {
        --form_size="",
        {mode="closed", button = "kwc3_1", img_button = "close_button.png", listname = "kwc3_1", inv_list={}, inv_size=0},
        {mode="opened", button = "kwc3_2", img_button = "open_button.png", listname = "kwc3_2", inv_list={}, inv_size=4*2},
        not_in_creative_inventory=1
        
    },
    ["kitchen_wooden_cabinet_4"] = {
        --form_size="",
        {mode="opened", button = "kwc4_1", img_button = "open_button.png", listname = "kwc4_1", inv_list={}, inv_size=4*2},
        {mode="opened", button = "kwc4_2", img_button = "open_button.png", listname = "kwc4_2", inv_list={}, inv_size=4*2},
        not_in_creative_inventory=1
        
    }
}
for cab, cab_boxes in pairs(kit_wood_cabs) do
    cabinet_num = cabinet_num + 1
    minetest.register_node("luxury_decor:"..cab, {
        description = "Kitchen Wooden Cabinet",
        visual_scale = 0.5,
        inventory_image = "kitchen_wooden_cabinet_with_two_drawers.png",
        mesh = cab..".obj",
        tiles = {"bright_wood_material.png"},
        paramtype = "light",
        paramtype2 = "facedir",
        groups = {choppy=3, not_in_creative_inventory = cab_boxes["not_in_creative_inventory"]},
        drawtype = "mesh",
        collision_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
        },
        sounds = default.node_sound_wood_defaults(),
        on_construct = function (pos)
            local name = minetest.get_node(pos).name
            local img_button1 = "image_button[0.5, 0;1, 2;" .. cab_boxes[1].img_button ..";" .. cab_boxes[1].button .. ";]"
            local img_button2 = "image_button[0.5, 3;1, 2;" .. cab_boxes[2].img_button .. ";" .. cab_boxes[2].button .. ";]"
            local list1 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[1].listname .. ";1.5, 0;4, 2]"
            local list2 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[2].listname .. ";1.5, 1;4, 2]"                                                           
            form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2 .. "]"
            --minetest.debug(dump(cabinets))
            cabinets.put_data_into_cabinet(pos, "kitchen_wooden_cabinet", tostring(cabinet_num), cab_boxes, {name=name, data=form})
            local inv = minetest.get_inventory({type="node", pos=pos})
            inv:set_list(cab_boxes[1].listname, cab_boxes[1].inv_list)
            inv:set_list(cab_boxes[2].listname, cab_boxes[2].inv_list)
            inv:set_size(cab_boxes[1].listname, cab_boxes[1].inv_size)
            inv:set_size(cab_boxes[2].listname, cab_boxes[2].inv_size)
            minetest.debug(dump(inv:get_list(cab_boxes[1].listname)))
            minetest.debug(dump(inv:get_list(cab_boxes[2].listname)))
            -- Fills "form_size" of each cabinet with needed size and "form_data" of each box with datas to build formspec with lists.
            --[[for cab2, cab_boxes2 in pairs(kit_wood_cabs) do
                cab_boxes2[cab2][form_size] = "size[8,4]"
                for box_num, cab_data in ipairs(cab_boxes2[2]) do
                    cab_data[box_num][form_data] = inv_elems[1] .. "0.2, 0.1;0.5, 2" .. inv_elems[2] 
                    if cab_data[
                end
            end]]
        end,
        on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
            minetest.show_formspec(clicker:get_player_name(), cab, form)  
        end,
        on_receive_fields = function (pos, formname, fields, sender)
            minetest.debug("AAAAAAAAAAAAAAAAAAA")
            local name = minetest.get_node(pos).name
            local generalized_name = string.match(name, '^._-')
            
            --[[for _, depart in ipairs(kit_wood_cabs[name]) do
               if depart[button] == formname then
                  if depart[mode] == "closed" then
                     for _, depart2 in ipairs(kit_wood_cabs) do
                        if ]]
            local defined_mode = cabinets.define_mode(formname, name)
            if defined_mode == "closed" then
               cabinets.open(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
            elseif defined_mode == "opened" then
               cabinets.close(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
            end
            
                   
        end
    })
end
So again a question: can i set any inventory with own name unlike 'main', 'craft' and etc ?

User avatar
AiTechEye
Member
Posts: 1000
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: Sweden

Re: Can`t set inventory list with own name.

by AiTechEye » Post

of course you can set inventory with its own name, but

Code: Select all

cabinet_num=0
form=""

kit_wood_cabs = {
		["kitchen_wooden_cabinet_1"] = {
				--form_size="",
				{mode="closed", button = "kwc1_1", img_button = "close_button.png", listname = "kwc1_1", inv_list={}, inv_size=1},
				{mode="closed", button = "kwc1_2", img_button = "close_button.png", listname = "kwc1_2", inv_list={}, inv_size=1}
				
		},
		["kitchen_wooden_cabinet_2"] = {
				--form_size="",
				{mode="opened", button = "kwc2_1", img_button = "open_button.png", listname = "kwc2_1", inv_list={}, inv_size=4*2},
				{mode="closed", button = "kwc2_2", img_button = "close_button.png", listname = "kwc2_2", inv_list={}, inv_size=0},
				not_in_creative_inventory=1
				
		},
		["kitchen_wooden_cabinet_3"] = {
				--form_size="",
				{mode="closed", button = "kwc3_1", img_button = "close_button.png", listname = "kwc3_1", inv_list={}, inv_size=0},
				{mode="opened", button = "kwc3_2", img_button = "open_button.png", listname = "kwc3_2", inv_list={}, inv_size=4*2},
				not_in_creative_inventory=1
				
		},
		["kitchen_wooden_cabinet_4"] = {
				--form_size="",
				{mode="opened", button = "kwc4_1", img_button = "open_button.png", listname = "kwc4_1", inv_list={}, inv_size=4*2},
				{mode="opened", button = "kwc4_2", img_button = "open_button.png", listname = "kwc4_2", inv_list={}, inv_size=4*2},
				not_in_creative_inventory=1
				
		}
}

for cab, cab_boxes in pairs(kit_wood_cabs) do
		cabinet_num = cabinet_num + 1
		minetest.register_node("luxury_decor:"..cab, {
			description = "Kitchen Wooden Cabinet",
			visual_scale = 0.5,
			inventory_image = "kitchen_wooden_cabinet_with_two_drawers.png",
			mesh = cab..".obj",
			tiles = {"bright_wood_material.png"},
			paramtype = "light",
			paramtype2 = "facedir",
			groups = {choppy=3, not_in_creative_inventory = cab_boxes["not_in_creative_inventory"]},
			drawtype = "mesh",
			collision_box = {
					type = "fixed",
					fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
			},
			selection_box = {
					type = "fixed",
					fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
			},
			sounds = default.node_sound_wood_defaults(),
			on_construct = function (pos)
					local name = minetest.get_node(pos).name
					local img_button1 = "image_button[0.5, 0;1, 2;" .. cab_boxes[1].img_button ..";" .. cab_boxes[1].button .. ";]"
					local img_button2 = "image_button[0.5, 3;1, 2;" .. cab_boxes[2].img_button .. ";" .. cab_boxes[2].button .. ";]"
					local list1 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[1].listname .. ";1.5, 0;4, 2]"
					local list2 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[2].listname .. ";1.5, 1;4, 2]"																						 
					form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2
				--	cabinets.put_data_into_cabinet(pos, "kitchen_wooden_cabinet", tostring(cabinet_num), cab_boxes, {name=name, data=form})
				--	local inv = minetest.get_inventory({type="node", pos=pos})


				local inv=minetest.get_meta(pos):get_inventory()
				inv:set_size(cab_boxes[1].listname, cab_boxes[1].inv_size)
				inv:set_size(cab_boxes[2].listname, cab_boxes[2].inv_size)
				inv:set_list(cab_boxes[1].listname, cab_boxes[1].inv_list)
				inv:set_list(cab_boxes[2].listname, cab_boxes[2].inv_list)


				--print(dump(inv:get_list(cab_boxes[1].listname)))
				--print(dump(inv:get_list(cab_boxes[2].listname)))
				-- Fills "form_size" of each cabinet with needed size and "form_data" of each box with datas to build formspec with lists.
				--[[
					for cab2, cab_boxes2 in pairs(kit_wood_cabs) do
						cab_boxes2[cab2][form_size] = "size[8,4]"
						for box_num, cab_data in ipairs(cab_boxes2[2]) do
								cab_data[box_num][form_data] = inv_elems[1] .. "0.2, 0.1;0.5, 2" .. inv_elems[2] 
								if cab_data[
						end
					end
				--]]
			end,
			on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
					minetest.show_formspec(clicker:get_player_name(), cab, form)	
			end,
			on_receive_fields = function (pos, formname, fields, sender)
					minetest.debug("AAAAAAAAAAAAAAAAAAA")
					local name = minetest.get_node(pos).name
					local generalized_name = string.match(name, '^._-')
					--[[for _, depart in ipairs(kit_wood_cabs[name]) do
						 if depart[button] == formname then
							if depart[mode] == "closed" then
								 for _, depart2 in ipairs(kit_wood_cabs) do
									if ]]
 --				 local defined_mode = cabinets.define_mode(formname, name)
					if defined_mode == "closed" then
						 cabinets.open(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
					elseif defined_mode == "opened" then
						cabinets.close(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
				end
			end
		})
end

i dont know why, but set inv:set_size before inv:set_list then it dont return nil

if you believe minetest.get_inventory is messing, try minetest.get_meta(pos):get_inventory() instead

removed .. "]" from
form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2 .. "]"

"inv_size" in "kitchen_wooden_cabinet_1" was 0 set those to 1

i don't know how the rest of the stuff works, but if it not working after restarting, is because the "form" variable's content is set in on_construct

then it works

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Can`t set inventory list with own name.

by Andrey01 » Post

Thank you, but i had already solved the problem before your reply. I made sure i can set a list with own name as i had been viewing a code with creating formspec of other mods.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests