meta data help

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

meta data help

by wcwyes » Sat Oct 05, 2013 23:33

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.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Oct 05, 2013 23:57

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
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sun Oct 06, 2013 02:37

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 '.'
Last edited by wcwyes on Sun Oct 06, 2013 19:17, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Wed Oct 09, 2013 22:48

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.
 

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

by rubenwardy » Thu Oct 10, 2013 08:10

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
Last edited by rubenwardy on Thu Oct 10, 2013 08:11, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Thu Oct 10, 2013 18:16

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
Last edited by wcwyes on Thu Oct 10, 2013 18:20, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Thu Oct 10, 2013 18:54

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)
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Fri Oct 11, 2013 19:27

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)
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Fri Oct 11, 2013 19:58

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.
 

ElectricSolstice
Member
 
Posts: 90
Joined: Tue Aug 20, 2013 02:00

by ElectricSolstice » Fri Oct 11, 2013 20:38

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.
Last edited by ElectricSolstice on Fri Oct 11, 2013 20:39, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Fri Oct 11, 2013 22:02

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.
 

ElectricSolstice
Member
 
Posts: 90
Joined: Tue Aug 20, 2013 02:00

by ElectricSolstice » Sat Oct 12, 2013 00:46

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sat Oct 12, 2013 00:58

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sat Oct 12, 2013 17:56

I've already made the individual tool/nodes Image
Last edited by wcwyes on Sat Oct 12, 2013 17:57, edited 1 time in total.
 

ElectricSolstice
Member
 
Posts: 90
Joined: Tue Aug 20, 2013 02:00

by ElectricSolstice » Sat Oct 12, 2013 17:59



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

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sat Oct 12, 2013 21:36

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sat Oct 12, 2013 23:34

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
Last edited by wcwyes on Sat Oct 12, 2013 23:37, edited 1 time in total.
 

ElectricSolstice
Member
 
Posts: 90
Joined: Tue Aug 20, 2013 02:00

by ElectricSolstice » Sun Oct 13, 2013 01:12

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
Last edited by ElectricSolstice on Sun Oct 13, 2013 01:17, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sun Oct 13, 2013 02:17

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
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Mon Oct 14, 2013 02:37

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
Last edited by wcwyes on Mon Oct 14, 2013 02:45, edited 1 time in total.
 

ElectricSolstice
Member
 
Posts: 90
Joined: Tue Aug 20, 2013 02:00

by ElectricSolstice » Mon Oct 14, 2013 23:44

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Tue Oct 15, 2013 00:09

thanks works great
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Tue Oct 15, 2013 00:52

how do I remove the item from bag 1?
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Wed Oct 16, 2013 20:04

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)
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Thu Oct 17, 2013 04:20

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"))
 

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

by rubenwardy » Thu Oct 17, 2013 08:08

I assume meta is defined, and so is "nodename" and "amount".
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Thu Oct 17, 2013 17:25

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:().
 

User avatar
fairiestoy
Member
 
Posts: 191
Joined: Sun Jun 09, 2013 19:25

by fairiestoy » Thu Oct 17, 2013 17:32

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.
Interesting about new things is, to figure out how it works ...
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Thu Oct 17, 2013 18:27

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
Last edited by wcwyes on Thu Oct 17, 2013 19:41, edited 1 time in total.
 

User avatar
fairiestoy
Member
 
Posts: 191
Joined: Sun Jun 09, 2013 19:25

by fairiestoy » Thu Oct 17, 2013 21:25

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.
Interesting about new things is, to figure out how it works ...
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 3 guests

cron