Page 1 of 2

meta data help

PostPosted: Sat Oct 05, 2013 23:33
by wcwyes
looking for specific commands for handling and controlling metadata, for players, special inventories, and world. Hoping to make some great mods with what I learn. I have 4 in mind and am almost done with another. just ran into problems with meta data. I thought I understood it but apparently I don't.

PostPosted: Sat Oct 05, 2013 23:57
by PilzAdam
There are two kinds of metadata:
Nodemeta:
Each node has an own meta object. The meta object has data stored in a table indexed by a strings and an inventory. It can be gotten via minetest.get_node_meta(pos). https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L805 https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1514

ItemStack metadata:
ItemStacks only have a single string for metadata. https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1666

PostPosted: Sun Oct 06, 2013 02:37
by wcwyes
Thanks looks like it will be alot of help.
PilzAdam wrote:There are two kinds of metadata:
Nodemeta:
Each node has an own meta object. The meta object has data stored in a table indexed by a strings and an inventory. It can be gotten via minetest.get_node_meta(pos). https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L805 https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1514

ItemStack metadata:
ItemStacks only have a single string for metadata. https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1666

It seems I still can't get it right though
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
if mode==1 then
    if player:get_inventory("bag1"):get_definition.description.suitcase==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

not sure what I did wrong, I always get
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
 function arguments expected near '.'

PostPosted: Wed Oct 09, 2013 22:48
by wcwyes
wcwyes wrote:Thanks looks like it will be alot of help.
It seems I still can't get it right though
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
if mode==1 then
    if player:get_inventory("bag1"):get_definition.description.suitcase==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

not sure what I did wrong, I always get
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
 function arguments expected near '.'

I think I'm making progress
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
if mode==1 then
    if player:get_inventory("bag1"):get_definition==suitcase then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

now it just says
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
 function arguments expected near '=='

not exactly sure how I'm supposed to write the argument.

PostPosted: Thu Oct 10, 2013 08:10
by rubenwardy
try

if mode==1 then
if player:get_inventory("bag1"):get_definition().description.suitcase==true then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
end


or

if mode==1 then
if player:get_inventory("bag1"):get_definition()==suitcase then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
end

PostPosted: Thu Oct 10, 2013 18:16
by wcwyes
Both instances crash the game on use
I get
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
attempt to index global 'player' (a nil value)

rubenwardy wrote:try

if mode==1 then
if player:get_inventory("bag1"):get_definition().description.suitcase==true then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
end


or

if mode==1 then
if player:get_inventory("bag1"):get_definition()==suitcase then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
end

PostPosted: Thu Oct 10, 2013 18:54
by wcwyes
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
if mode==1 then
    if user:get_player_name():get_inventory("bag1"):get_definition()==suitcase then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

with this I get
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
attempt to call method 'get_inventory' (a nil value)

PostPosted: Fri Oct 11, 2013 19:27
by wcwyes
tried a different method
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
if mode==1 then
    if user:get_player_name():get_inventory("bag1"):get_definition():get_current_modname()==suitcase then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

I still get
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
attempt to call method 'get_inventory' (a nil value)

PostPosted: Fri Oct 11, 2013 19:58
by wcwyes
tried 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
if mode==1 then
    if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

and got
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
attempt to call global 'get_current_modname' (a nil value)

I think I'm on the right track, someone help, please.

PostPosted: Fri Oct 11, 2013 20:38
by ElectricSolstice
wcwyes wrote:tried 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
if mode==1 then
    if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

and got
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
attempt to call global 'get_current_modname' (a nil value)

I think I'm on the right track, someone help, please.


Someone correct me if I'm wrong but I would guess get_player_name would return a string rather than the data of a player. Then, you were trying to do get_definition on an Inventory object. When looking at the api documentation, there's a get_definition method for ItemStack, which are contained in the lists of an Inventory, but the Inventory itself doesn't appear to have a get_definition method. Also, get_inventory takes 0 arguments, ignoring the fact that the colon makes a method put the calling table in as the first argument. Not only that, but you have a "]" where i think you meant "}"

The code could probably use something along the lines of
if user:is_player() then
local bag_one = user:get_inventory():get_list("bag1")

However, I haven't dealt with the lists themselves, so I don't even know yet how to use them.

Also, the problem is, I can't tell from the code shown what you're trying to do. Is this what happens when you right click on something or what? Because a node is something that is one of those cubes out in the world outside the player. However, in the code, I see both return itemstack and minetest.get_node.

Give a better explanation of what you're trying to achieve and/or show more code. Most important right now would be an explanation.

PostPosted: Fri Oct 11, 2013 22:02
by wcwyes
I've created a node/tool(i.e. a tool that places a node version of itself)that is a chest and a bag. I'm working on creating a tool to look at the bags and place the node version of that bag and transfer the inventory over to it and then remove the tool from the inventory. I'm using the screwdriver as a guide I've stripped it down to barely the rotating function and now I'm building mode1 up. think of mode1 being
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
on_use = function(itemstack, user, pointed_thing)
if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
return itemstack
end,

ElectricSolstice wrote:
wcwyes wrote:tried 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
if mode==1 then
    if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

and got
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
attempt to call global 'get_current_modname' (a nil value)

I think I'm on the right track, someone help, please.


Someone correct me if I'm wrong but I would guess get_player_name would return a string rather than the data of a player. Then, you were trying to do get_definition on an Inventory object. When looking at the api documentation, there's a get_definition method for ItemStack, which are contained in the lists of an Inventory, but the Inventory itself doesn't appear to have a get_definition method. Also, get_inventory takes 0 arguments, ignoring the fact that the colon makes a method put the calling table in as the first argument. Not only that, but you have a "]" where i think you meant "}"

The code could probably use something along the lines of
if user:is_player() then
local bag_one = user:get_inventory():get_list("bag1")

However, I haven't dealt with the lists themselves, so I don't even know yet how to use them.

Also, the problem is, I can't tell from the code shown what you're trying to do. Is this what happens when you right click on something or what? Because a node is something that is one of those cubes out in the world outside the player. However, in the code, I see both return itemstack and minetest.get_node.

Give a better explanation of what you're trying to achieve and/or show more code. Most important right now would be an explanation.

PostPosted: Sat Oct 12, 2013 00:46
by ElectricSolstice
wcwyes wrote:I've created a node/tool(i.e. a tool that places a node version of itself)that is a chest and a bag. I'm working on creating a tool to look at the bags and place the node version of that bag and transfer the inventory over to it and then remove the tool from the inventory. I'm using the screwdriver as a guide I've stripped it down to barely the rotating function and now I'm building mode1 up. think of mode1 being
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
on_use = function(itemstack, user, pointed_thing)
if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
return itemstack
end,

ElectricSolstice wrote:
wcwyes wrote:tried 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
if mode==1 then
    if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
end

and got
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
attempt to call global 'get_current_modname' (a nil value)

I think I'm on the right track, someone help, please.


Someone correct me if I'm wrong but I would guess get_player_name would return a string rather than the data of a player. Then, you were trying to do get_definition on an Inventory object. When looking at the api documentation, there's a get_definition method for ItemStack, which are contained in the lists of an Inventory, but the Inventory itself doesn't appear to have a get_definition method. Also, get_inventory takes 0 arguments, ignoring the fact that the colon makes a method put the calling table in as the first argument. Not only that, but you have a "]" where i think you meant "}"

The code could probably use something along the lines of
if user:is_player() then
local bag_one = user:get_inventory():get_list("bag1")

However, I haven't dealt with the lists themselves, so I don't even know yet how to use them.

Also, the problem is, I can't tell from the code shown what you're trying to do. Is this what happens when you right click on something or what? Because a node is something that is one of those cubes out in the world outside the player. However, in the code, I see both return itemstack and minetest.get_node.

Give a better explanation of what you're trying to achieve and/or show more code. Most important right now would be an explanation.



Hmm, so it's the the tool you're using that contains an inventory and you want the tool to turn into a node with the same inventory?

If you want the tool to deploy itself maybe try something along the lines of

on use = function(itemstack, user, pointed_thing)
if itemstack:get_name() == "suitcase:bag" then
local pt = pointed_thing
if minetest.get_node(pt.above).name == "air" then
local itemstack_meta = itemstack:get_meta()
--haven't dealt with itemstack meta before so
--figure out what the difference is between it and
--a node's metadata and create a conversion
--function as neccesary
local node_meta_table,
node_inventory_table = yourConvFunc(itemstack_meta)
minetest.set_node(pt.above,
{name="suitcase:general_node"})
local node_meta = minetest.get_meta(pt.above)
node_meta:set_string("formspec",node_form_spec)
local key,meta_data, inv_data
for key,meta_data in pairs(node_meta_table) do
if type(meta_data) == "int" then
node_meta:set_int(key,meta_data)
elseif type(meta_data == "string") then
node_meta:set_string(key,meta_data)
end
end
local inv = node_meta:get_inventory()
--key is listname and inv_data are stacks
--or key can be listname and inv_data are lists
for key,inv_data in pairs(node_inventory_table) do
--code for inv_data = stacks
local stack
for _,stack in pairs(inv_data) do
inv:add_item(key,stack)
end
--code for inv_data = list
inv:set_list(key,inv_data)
end
--return empty item stack since tool is now a node
return ItemStack(nil)
end
end
--leave item stack alone since it didn't met conditions
return nil
end

I haven't tried it so the code is most likely wrong, has errors, and/or has more code than neccessary but should give an idea of maybe how to do it.

PostPosted: Sat Oct 12, 2013 00:58
by wcwyes
No the tool I'm using is supposed to target the suitcase in the bag slots for unified inventory and create the node associated with it and deploy the meta data from the inventory bagcontents1 then remove the bag from bag slot 1.
ElectricSolstice wrote:
wcwyes wrote:I've created a node/tool(i.e. a tool that places a node version of itself)that is a chest and a bag. I'm working on creating a tool to look at the bags and place the node version of that bag and transfer the inventory over to it and then remove the tool from the inventory. I'm using the screwdriver as a guide I've stripped it down to barely the rotating function and now I'm building mode1 up. think of mode1 being
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
on_use = function(itemstack, user, pointed_thing)
if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt = pointed_thing
            minetest.get_node(pt.above, {name="suitcase:general_node"])
            return itemstack
        end
    end
return itemstack
end,

ElectricSolstice wrote:
Someone correct me if I'm wrong but I would guess get_player_name would return a string rather than the data of a player. Then, you were trying to do get_definition on an Inventory object. When looking at the api documentation, there's a get_definition method for ItemStack, which are contained in the lists of an Inventory, but the Inventory itself doesn't appear to have a get_definition method. Also, get_inventory takes 0 arguments, ignoring the fact that the colon makes a method put the calling table in as the first argument. Not only that, but you have a "]" where i think you meant "}"

The code could probably use something along the lines of
if user:is_player() then
local bag_one = user:get_inventory():get_list("bag1")

However, I haven't dealt with the lists themselves, so I don't even know yet how to use them.

Also, the problem is, I can't tell from the code shown what you're trying to do. Is this what happens when you right click on something or what? Because a node is something that is one of those cubes out in the world outside the player. However, in the code, I see both return itemstack and minetest.get_node.

Give a better explanation of what you're trying to achieve and/or show more code. Most important right now would be an explanation.



Hmm, so it's the the tool you're using that contains an inventory and you want the tool to turn into a node with the same inventory?

If you want the tool to deploy itself maybe try something along the lines of

on use = function(itemstack, user, pointed_thing)
if itemstack:get_name() == "suitcase:bag" then
local pt = pointed_thing
if minetest.get_node(pt.above).name == "air" then
local itemstack_meta = itemstack:get_meta()
--haven't dealt with itemstack meta before so
--figure out what the difference is between it and
--a node's metadata and create a conversion
--function as neccesary
local node_meta_table,
node_inventory_table = yourConvFunc(itemstack_meta)
minetest.set_node(pt.above,
{name="suitcase:general_node"})
local node_meta = minetest.get_meta(pt.above)
node_meta:set_string("formspec",node_form_spec)
local key,meta_data, inv_data
for key,meta_data in pairs(node_meta_table) do
if type(meta_data) == "int" then
node_meta:set_int(key,meta_data)
elseif type(meta_data == "string") then
node_meta:set_string(key,meta_data)
end
end
local inv = node_meta:get_inventory()
--key is listname and inv_data are stacks
--or key can be listname and inv_data are lists
for key,inv_data in pairs(node_inventory_table) do
--code for inv_data = stacks
local stack
for _,stack in pairs(inv_data) do
inv:add_item(key,stack)
end
--code for inv_data = list
inv:set_list(key,inv_data)
end
--return empty item stack since tool is now a node
return ItemStack(nil)
end
end
--leave item stack alone since it didn't met conditions
return nil
end

I haven't tried it so the code is most likely wrong, has errors, and/or has more code than neccessary but should give an idea of maybe how to do it.

PostPosted: Sat Oct 12, 2013 17:56
by wcwyes
I've already made the individual tool/nodes Image

PostPosted: Sat Oct 12, 2013 17:59
by ElectricSolstice


Cool, figured out how to do what you were wanting? Should be able to be done.

PostPosted: Sat Oct 12, 2013 21:36
by wcwyes
ElectricSolstice wrote:


Cool, figured out how to do what you were wanting? Should be able to be done.

I haven't figured out the next step which is targeting the bag slots and setting them on the ground(with their inventory in them) using a tool I call the briefcase. The problem I'm trying to overcome is checking for a mod name and if it is suitcase then a node would be placed.

PostPosted: Sat Oct 12, 2013 23:34
by wcwyes
the reason I don't show all of my code is because there's still alot of unnecessary screwdriver code left in the code, but I'll give you 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
minetest.register_tool("suitcase:briefcase", {
        description = "Briefcase",
        inventory_image = "briefcase.png",
        on_use = function(itemstack, user, pointed_thing)
        use_handler(itemstack, user, pointed_thing)
        return itemstack
        end,
})

for i=1,4,1 do
minetest.register_tool("suitcase:briefcase"..i, {
        description "Briefcase targeting slot"..i
        inventory_image = "briefcase.png"^"tool_mode"..i..".png",
        wield_image = "briefcase.png",
        groups = {not_in_creative_inventory=1},
        on_use = function(itemstack, user, pointed_thing)
        use_handler(itemstack, user, pointed_thing)
        return itemstack
        end,
})
end

and
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
function use_handler (itemstack, user, pointed_thing)
        local keys=user:get_player_control()
        local player_name=user:get_player_name()
        local item=itemstack:to_table()
        if item["metadata"]=="" or keys["sneak"]==true then return briefcase_setslot(user, itemstack) end
        local mode=tonumber((item[metadata"]))
        if pointed_thing.type~="node"then return end
        local pos=minetest.get_pointed_thing_position(pointed_thing.above)
        local node=minetest.env:get_node(pos)
        local node_name=node.name
                if minetest.registered_nodes[node_name].drawtype == "nodebox" then
                        end
                if node.param2==nil then return end
                        local n = node.param2
                        local axisdir=math.floor(n/4)
                        local rotation=n-axisdir*4
                        if mode==1 then
                            if user:get_inventory():get_list("bag1"):get_current_modname()==suitcase then
                                local pt = pointed_thing
                                if minetest.get_node(pt.above).name=="air" then
                                    local pt=pointed_thing
                                    minetest.set_node(pt.above, {name="suitcase:general_node"})
                                    return itemstack
                                end
                            end
                        end

the point of this code is to place the specified node when any suitcase is in bag slot 1

PostPosted: Sun Oct 13, 2013 01:12
by ElectricSolstice
wcwyes wrote:
ElectricSolstice wrote:


Cool, figured out how to do what you were wanting? Should be able to be done.

I haven't figured out the next step which is targeting the bag slots and setting them on the ground(with their inventory in them) using a tool I call the briefcase. The problem I'm trying to overcome is checking for a mod name and if it is suitcase then a node would be placed.


Checking for a mod name? Well, when that tool was registered, looks like you registered it as "suitcase:briefcase", so take a look at lua string library. I'm guessing you want something along the lines of

--assumes that bag1 list is of size 1,1 in the formspec
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
--code to place node and add metadata
end

PostPosted: Sun Oct 13, 2013 02:17
by wcwyes
ElectricSolstice wrote:
--assumes that bag1 list is of size 1,1 in the formspec
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
--code to place node and add metadata
end

thanks it works great
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
if mode==1 then
    local bag1_stack = user:get_inventory():get_stack("bag1",1)
    local suitcase_name =  bag1_stack:get_name()
    if string.match(suitcase_name,"suitcase:") then
        local pt = pointed_thing
        if minetest.get_node(pt.above).name=="air" then
            local pt=pointed_thing
            minetest.set_node(pt.above, {name="suitcase:general_node"})
            return itemstack
        end
    end
end
I'll try to do rest on my own but will be back if I need help

PostPosted: Mon Oct 14, 2013 02:37
by wcwyes
I've got it transferring the data but, it won't show player inventory(I feel like there's a better way to do it too)
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 S
if minetest.get_modpath("intllib")) then
    dofile(minetest.get_modpath("initllib").."/initllib.lua")
    S = initllib.Getter(minetest.get_current_modname())
else
    S = function ( s ) return s end
end
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
if mode==1 then
                            local bag1_stack = user:get_inventory():get_stack("bag1",1)
                            local suitcase_name = bag1_stack:get_name()
                            if string.match(suitcase_name,"suitcase:") then
                                local pt = pointed_thing
                                if minetest.get_node(pt.above).name=="air" then
                                    local pt = pointed_thing
                                    local bag1_stack = user:get_inventory():get_stack("bag1",1)
                                    local suitcase_name = bag1_stack:get_name()
                                    minetest.set_node(pt.above, {name=suitcase_name .. "_node"})
--\/\/fixme\/\/
                                    local meta =minetest.env:get_meta(pt.above)
                                    local inv = meta:get_inventory()
                                    local player_inv = user:get_inventory()
                                    inv:set_size("main", 24)

                                    local empty_list = inv:get_list("bag1contents")
                                    inv:set_list("main", player_inv:get_list("bag1contents"))
                                    player_inv:set_list("bag1contents", empty_list)

                                    meta:set_string("formspec", "size[10,10;]"..
                                        "list[current_name;main;0,0;8,3]"..
                                        "list[current_player;main;1,6;8,4;]")
                                    meta:set_string("infotext", S("suitcase"))
                                    local inv = meta:get_inventory()
                                    inv:set_size("main",24)
--/\/\fixme/\/\
                                    return itemstack
                                end
                            end
            end

PostPosted: Mon Oct 14, 2013 23:44
by ElectricSolstice
wcwyes wrote:I've got it transferring the data but, it won't show player inventory(I feel like there's a better way to do it too)
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 S
if minetest.get_modpath("intllib")) then
    dofile(minetest.get_modpath("initllib").."/initllib.lua")
    S = initllib.Getter(minetest.get_current_modname())
else
    S = function ( s ) return s end
end
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
if mode==1 then
                            local bag1_stack = user:get_inventory():get_stack("bag1",1)
                            local suitcase_name = bag1_stack:get_name()
                            if string.match(suitcase_name,"suitcase:") then
                                local pt = pointed_thing
                                if minetest.get_node(pt.above).name=="air" then
                                    local pt = pointed_thing
                                    local bag1_stack = user:get_inventory():get_stack("bag1",1)
                                    local suitcase_name = bag1_stack:get_name()
                                    minetest.set_node(pt.above, {name=suitcase_name .. "_node"})
--\/\/fixme\/\/
                                    local meta =minetest.env:get_meta(pt.above)
                                    local inv = meta:get_inventory()
                                    local player_inv = user:get_inventory()
                                    inv:set_size("main", 24)

                                    local empty_list = inv:get_list("bag1contents")
                                    inv:set_list("main", player_inv:get_list("bag1contents"))
                                    player_inv:set_list("bag1contents", empty_list)

                                    meta:set_string("formspec", "size[10,10;]"..
                                        "list[current_name;main;0,0;8,3]"..
                                        "list[current_player;main;1,6;8,4;]")
                                    meta:set_string("infotext", S("suitcase"))
                                    local inv = meta:get_inventory()
                                    inv:set_size("main",24)
--/\/\fixme/\/\
                                    return itemstack
                                end
                            end
            end


Hmm, I'm not sure. Formspecs can be fickle though or seem that way.
Try adding a semicolon to "list[current_name;main;0,0;8,3;]

Let me know if that works. Could be a problem with the formspec, could be something else.

PostPosted: Tue Oct 15, 2013 00:09
by wcwyes
thanks works great

PostPosted: Tue Oct 15, 2013 00:52
by wcwyes
how do I remove the item from bag 1?

PostPosted: Wed Oct 16, 2013 20:04
by wcwyes
I got it to remove the suitcase from bag1 by adding this to the end before return itemstack, but for it to take effect I have to log out and log back in. Any suggestions?
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
user:get_inventory():set_stack("bag1",1, Empty)

PostPosted: Thu Oct 17, 2013 04:20
by wcwyes
I also tried this which didn't work at all.
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
user:get_inventory():remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))

PostPosted: Thu Oct 17, 2013 08:08
by rubenwardy
I assume meta is defined, and so is "nodename" and "amount".

PostPosted: Thu Oct 17, 2013 17:25
by wcwyes
rubenwardy wrote:I assume meta is defined, and so is "nodename" and "amount".

you make a good point so I tried
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 bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
user:get_inventory():remove_item("bag1", {name=suitcase_name.." "..1})
but it still did nothing at least the other code did what I wanted(just after I logged out:().

PostPosted: Thu Oct 17, 2013 17:32
by fairiestoy
I suggest that you set some debug info. Like what name is printing 'suitcase_name'. It might be possible that you are even getting a nil value here, if your bag has more than one inventory slot and you didn't put the item in the first index. Since thats the only indexing your asking for in your code.

PostPosted: Thu Oct 17, 2013 18:27
by wcwyes
fairiestoy wrote:I suggest that you set some debug info. Like what name is printing 'suitcase_name'. It might be possible that you are even getting a nil value here, if your bag has more than one inventory slot and you didn't put the item in the first index. Since thats the only indexing your asking for in your code.

I'm trying to delete the bag from bag1 slot. The inventory has already been transfered
bag1 only has one index by default, you're thinking of bag1contents

PostPosted: Thu Oct 17, 2013 21:25
by fairiestoy
Im sorry, my bad. Got the wrong case. Anyway, i read a bit through the unified inventory and stumbled over something. You tried to access the inventory list bag1 from the player inventory. But it seems the bags themself are not stored as bag1 bag2 bagn [..] but within the inventory list '<player name>_bags'. Correct me if im wrong, but this line seems to be relevant in this case: Unified Inventory

Also this line shows maybe what i mean: Unified Formspec

Since i didn't find any call in your code to exactly that inventory list, it may be possible that this is the issue.