meta data help

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

by wcwyes » Fri Oct 18, 2013 04:30

fairiestoy wrote: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.

If this was the case my code wouldn't do anything at all if you look at my earlier posts you'll see that I use the same convention to make sure the modname is suitcase, and then again to place the node associated with the tool(not in my posts) all of these work. bags is a direct reference to the button not the bag slots. look at line 28 in the code you sent to me to see the naming convention.
 

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

by fairiestoy » Fri Oct 18, 2013 16:03

And thats what i meant by my previous post. You are currently working on the 'bagcontents' itself and want to delete the bag as a item from the inventory slot shown in the unified inventory when clicking on the Bag icon in the bottom. While your metadata code works well, since you are in the correct list, the bags put into the slots are within the inventory list mentioned in the lines i quoted. As i already told you, compare your line 28 and the formspecs with the lines from the top of the file i mentioned.

Otherwise you could also ask this on irc to the specific devs if necessary.
Last edited by fairiestoy on Fri Oct 18, 2013 16:04, edited 1 time in total.
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Fri Oct 18, 2013 17:55

fairiestoy wrote:And thats what i meant by my previous post. You are currently working on the 'bagcontents' itself and want to delete the bag as a item from the inventory slot shown in the unified inventory when clicking on the Bag icon in the bottom. While your metadata code works well, since you are in the correct list, the bags put into the slots are within the inventory list mentioned in the lines i quoted. As i already told you, compare your line 28 and the formspecs with the lines from the top of the file i mentioned.

Otherwise you could also ask this on irc to the specific devs if necessary.

bags is a button line 23
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
unified_inventory.register_button("bags", {

bag1 is the reference to the bag as an item line 29
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 stack = player:get_inventory():get_stack("bag"..i, 1){

bag1contents is the reference to tthe items you're carrying line 34
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
formspec = formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
You're wrong again I've already got the contents to transfer using bag1contents which is referenced on line 34 in the Unified_inventory code. All my meta references are correct and tested. I hope this helps you.
Last edited by wcwyes on Fri Oct 18, 2013 18:25, edited 1 time in total.
 

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

by fairiestoy » Fri Oct 18, 2013 19:11

Im sorry, but im afraid that i am right. The inventory you were trying to access is not within the players object reference.

Try this code, it worked local. As i said, better read through the lines carefully:

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
--[[
Code example to show how to erase
the bag from the bag slot of the
unified inventory

]]

local function bag_test( name, param )
    local player = minetest.get_player_by_name( name )
    local p_inventory = player:get_inventory()
    local bag_list = minetest.get_inventory( {type='detached', name=name..'_bags' } )
    if bag_list then
        -- looks like we have the bag list
        local bag_inv = bag_list:get_stack( 'bag1', 1 )
        if bag_inv then
            if bag_inv:get_name():sub( 1, 3 ) == 'uni' then
                bag_list:remove_item( 'bag1', bag_inv )
                p_inventory:remove_item( 'bag1', {name='unified_inventory:bag_small'} )
            else
                print( 'Stack in bag does not fit expected one' )
                print( bag_inv:get_name() )
            end
        else
            print( 'bag_inv is nil' )
        end
    else
        print( 'bag_list is nil or false' )
    end
end

minetest.register_chatcommand("erase_bag", {
    params = "",
    description = "Erases the bag of the unified inventory slot",
    func = bag_test
})


Edit:
This works only if you put the bag in slot bag1, i didn't made any checks for other slots.
Edit 2:
Please note that i used the small bag from the unified inventory in order to test this. So replace
nodenames etc. Also you were right to a specific point, you have to access the user related inventory. But
thats not the only place.
Last edited by fairiestoy on Fri Oct 18, 2013 19:19, edited 1 time in total.
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Sat Oct 19, 2013 01:22

I attemted to impliment your code as a self acting fuction but it doesn't seem to do anything. Try to put the code in a tool on use, there's no need for me to test your code because it still doesn't serve the purpose I need.
fairiestoy wrote:Im sorry, but im afraid that i am right. The inventory you were trying to access is not within the players object reference.by the way what is uni?

Try this code, it worked local. As i said, better read through the lines carefully:

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
--[[
Code example to show how to erase
the bag from the bag slot of the
unified inventory

]]

local function bag_test( name, param )
    local player = minetest.get_player_by_name( name )
    local p_inventory = player:get_inventory()
    local bag_list = minetest.get_inventory( {type='detached', name=name..'_bags' } )
    if bag_list then
        -- looks like we have the bag list
        local bag_inv = bag_list:get_stack( 'bag1', 1 )
        if bag_inv then
            if bag_inv:get_name():sub( 1, 3 ) == 'uni' then
                bag_list:remove_item( 'bag1', bag_inv )
                p_inventory:remove_item( 'bag1', {name='unified_inventory:bag_small'} )
            else
                print( 'Stack in bag does not fit expected one' )
                print( bag_inv:get_name() )
            end
        else
            print( 'bag_inv is nil' )
        end
    else
        print( 'bag_list is nil or false' )
    end
end

minetest.register_chatcommand("erase_bag", {
    params = "",
    description = "Erases the bag of the unified inventory slot",
    func = bag_test
})


Edit:
This works only if you put the bag in slot bag1, i didn't made any checks for other slots.
Edit 2:
Please note that i used the small bag from the unified inventory in order to test this. So replace
nodenames etc. Also you were right to a specific point, you have to access the user related inventory. But
thats not the only place.
Edit:I don't need any clauses for the bag to be removed because I already set up clauses that it would never get this far, I prefer to use a code that will delete the item regardless of what it is.
Edit:What version are you using?
Last edited by wcwyes on Sat Oct 19, 2013 03:12, edited 1 time in total.
 

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

by fairiestoy » Sat Oct 19, 2013 11:25

I tried my code as single mod, so put this code in a init.lua in a new folder within the mod directory. It was for testing purpose and not to show you an entire ready-to-use function. Also, as i mentioned, this was only a testcode and was done with the unified_inventory:small_bag just to have an item that fits there. My code should only show you what inventory list you should access in order to delete the item. If you are not willing to implement the necessary lines in your code, than im sorry for that. But in my opinion the sample is clear enough to extract the deletion process and include it in your code.

Did you ever tried to use the command or change the name of the item within the slot that should be deleted?

What version of what? Minetest version, unified inventory version. Be more specific if you need data. Even though i can't see any need for you to know what version of the inventory or minetest im using. It should make no difference as long as the interface of the unified inventory has changed radically.
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Sat Oct 19, 2013 19:08

I tried chaning everything accordingly and it still didn't work, I was referring to your minetest version. Minetest 4.8 handles things alot different than 4.7. My server owner won't goto 4.8 until it is stable. So I'm writing this for 4.7.
fairiestoy wrote:I tried my code as single mod, so put this code in a init.lua in a new folder within the mod directory. It was for testing purpose and not to show you an entire ready-to-use function. Also, as i mentioned, this was only a testcode and was done with the unified_inventory:small_bag just to have an item that fits there. My code should only show you what inventory list you should access in order to delete the item. If you are not willing to implement the necessary lines in your code, than im sorry for that. But in my opinion the sample is clear enough to extract the deletion process and include it in your code.

Did you ever tried to use the command or change the name of the item within the slot that should be deleted?

What version of what? Minetest version, unified inventory version. Be more specific if you need data. Even though i can't see any need for you to know what version of the inventory or minetest im using. It should make no difference as long as the interface of the unified inventory has changed radically.
 

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

by fairiestoy » Sat Oct 19, 2013 19:18

I have a suggestion: Upload everything to Github and post your repository here. Then its much easier to look through your code. If its only one single file you could also use a code paste service like pastebin.
for this test i used Minetest 0.4.7-bc5db9b
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Sat Oct 19, 2013 19:28

this is the extent of my code and it works fine at what I was trying. It places a suitcase with the node name associated with it, it moves all of the inventory over I just need a line/argument/function to finish it and remove the item(what ever it may be) from bag1.
NOTE:mode==1 is on_use
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"})

                                    local meta =minetest.env:get_meta(pt.above)
                                    local inv = meta:get_inventory()
                                    local player_inv = user:get_inventory()
                                    local slots = bag1_stack:get_definition().groups.bagslots
                                    inv:set_size("main", slots)

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

                                    meta = minetest.env:get_meta(pos)
                                    meta:from_table(meta0)
                                    local item=itemstack:to_table()
                                    local item_wear=tonumber((item["wear"]))
                                    item_wear=item_wear+327
                                    if item_wear>65535 then itemstack:clear() return itemstack end
                                    item["wear"]=tostring(item_wear)
                                    itemstack:replace(item)
                                    return itemstack
                                end                           
                            end
            end


The code below works but only after I log out and then log back in
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)
Last edited by wcwyes on Sat Oct 19, 2013 19:35, edited 1 time in total.
 

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

by fairiestoy » Sat Oct 19, 2013 23:33

Ok, although i totally dislike doing this, tell me how the following code behaves.

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

                                    local meta =minetest.env:get_meta(pt.above)
                                    local inv = meta:get_inventory()
                                    local player_inv = user:get_inventory()
                                    local slots = bag1_stack:get_definition().groups.bagslots
                                    inv:set_size("main", slots)

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

                                    === Until here, we removed the bag[b]contents[/b], time to remove the bag itself

                                    local bag_list = minetest.get_inventory( {type='detached', name=user:get_player_name()..'_bags' } )
                                    if bag_list then
                                        local bag_inv = bag_list:get_stack( 'bag1', 1 )
                                        if bag_inv then
                                            bag_list:remove_item( 'bag1', bag_inv )
                                            player_inv:remove_item( 'bag1', {name=suitcase_name} )
                                        else
                                            print( 'bag_inv is nil' )
                                        end
                                    else
                                        print( 'bag_list is nil or false' )
                                    end
                                    === now everything should be ok

                                    meta = minetest.env:get_meta(pos)
                                    meta:from_table(meta0)
                                    local item=itemstack:to_table()
                                    local item_wear=tonumber((item["wear"]))
                                    item_wear=item_wear+327
                                    if item_wear>65535 then itemstack:clear() return itemstack end
                                    item["wear"]=tostring(item_wear)
                                    itemstack:replace(item)
                                    return itemstack
                                end                           
                            end
            end
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Sun Oct 20, 2013 00:03

works great I must have implemented it wrong when I tried to implement it. Thanks for the help.
fairiestoy wrote:Ok, although i totally dislike doing this, tell me how the following code behaves.

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

                                    local meta =minetest.env:get_meta(pt.above)
                                    local inv = meta:get_inventory()
                                    local player_inv = user:get_inventory()
                                    local slots = bag1_stack:get_definition().groups.bagslots
                                    inv:set_size("main", slots)

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

                                    === Until here, we removed the bag[b]contents[/b], time to remove the bag itself

                                    local bag_list = minetest.get_inventory( {type='detached', name=user:get_player_name()..'_bags' } )
                                    if bag_list then
                                        local bag_inv = bag_list:get_stack( 'bag1', 1 )
                                        if bag_inv then
                                            bag_list:remove_item( 'bag1', bag_inv )
                                            player_inv:remove_item( 'bag1', {name=suitcase_name} )
                                        else
                                            print( 'bag_inv is nil' )
                                        end
                                    else
                                        print( 'bag_list is nil or false' )
                                    end
                                    === now everything should be ok

                                    meta = minetest.env:get_meta(pos)
                                    meta:from_table(meta0)
                                    local item=itemstack:to_table()
                                    local item_wear=tonumber((item["wear"]))
                                    item_wear=item_wear+327
                                    if item_wear>65535 then itemstack:clear() return itemstack end
                                    item["wear"]=tostring(item_wear)
                                    itemstack:replace(item)
                                    return itemstack
                                end                           
                            end
            end
 

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

by wcwyes » Sun Oct 20, 2013 21:43

Trying to reverse the process now I tried adding the suitcase back to the bag1 slot using
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 pos = minetest.get_pointed_thing_position(pointed_thing, above)
    local node = minetest.env:get_node(pos)
    local node_name = node.name
    local drop_name == minetest.registered_nodes[node_name].drop
    if drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end
any clue where I messed up? or do I have the wrong idea?
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Mon Oct 21, 2013 03:30

wcwyes wrote:Trying to reverse the process now I tried adding the suitcase back to the bag1 slot using
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 pos = minetest.get_pointed_thing_position(pointed_thing, above)
    local node = minetest.env:get_node(pos)
    local node_name = node.name
    local drop_name == minetest.registered_nodes[node_name].drop
    if drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end
any clue where I messed up? or do I have the wrong idea?


Unless I am misremembering, the pointed_thing under is the actual node that is being pointed at. I haven't looked any closer yet but that might be part of the problem.
 

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

by wcwyes » Mon Oct 21, 2013 04:09

I believe you're right I think I was using above to check for air and what not, tried it but it's still not adding the suitcase to bag slot one so there must be another problem too, but thanks for that reminder. Went ahead and changed it.
LionsDen wrote:
wcwyes wrote:Trying to reverse the process now I tried adding the suitcase back to the bag1 slot using
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 pos = minetest.get_pointed_thing_position(pointed_thing, above)
    local node = minetest.env:get_node(pos)
    local node_name = node.name
    local drop_name == minetest.registered_nodes[node_name].drop
    if drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end
any clue where I messed up? or do I have the wrong idea?


Unless I am misremembering, the pointed_thing under is the actual node that is being pointed at. I haven't looked any closer yet but that might be part of the problem.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Mon Oct 21, 2013 07:08

I haven't worked with detached inventories or the players inventory much but I think I see something that might cause an issue, not sure if it is correct usage or not. The line below has a colon after suitcase. Shouldn't it just be suitcase?

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 drop_name == "suitcase:" then
 

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

by wcwyes » Mon Oct 21, 2013 13:10

The colon emphasizes that it's anything from the mod name
LionsDen wrote:I haven't worked with detached inventories or the players inventory much but I think I see something that might cause an issue, not sure if it is correct usage or not. The line below has a colon after suitcase. Shouldn't it just be suitcase?

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 drop_name == "suitcase:" then

went ahead and changed it to
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 string.match(drop_name, "suitcase:") then

EDIT:now I get "attempt to index global 'player_inv'(a nil value)"
EDIT:defined local player_inv 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 player_inv = user:get_inventory()

EDIT:now it's back to doing nothing
Last edited by wcwyes on Mon Oct 21, 2013 13:38, edited 1 time in total.
 

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

by fairiestoy » Mon Oct 21, 2013 15:22

Not to be rude, but did you ever inserted any debug prints in order to find out what your script is doing? I suggest you put this in, because i think its the problem:

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 drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            print( 'Checking if the type of bag1_inv: ', type( bag1_inv ) ) -- <<< inserted this line
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end


I would bet it returns nil
Last edited by fairiestoy on Mon Oct 21, 2013 15:23, edited 1 time in total.
Interesting about new things is, to figure out how it works ...
 

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

by wcwyes » Mon Oct 21, 2013 19:31

I did but they didn't return, I also entered the debug that you suggested and it returned
Checking if the type of bag1_inv:
fairiestoy wrote:Not to be rude, but did you ever inserted any debug prints in order to find out what your script is doing? I suggest you put this in, because i think its the problem:

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 drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            print( 'Checking if the type of bag1_inv: ', type( bag1_inv ) ) -- <<< inserted this line
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end


I would bet it returns nil

EDIT:If you read my post I also changed the code to
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 pos = minetest.get_pointed_thing_position(pointed_thing, under)
    local node = minetest.env:get_node(pos)
    local node_name = node.name
    local drop_name == minetest.registered_nodes[node_name].drop
    if string.match(drop_name, "suitcase:") then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                local player_inv = user:get_inventory()
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end
Last edited by wcwyes on Mon Oct 21, 2013 19:52, edited 1 time in total.
 

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

by wcwyes » Tue Oct 22, 2013 01:02

What about the references to the item drop do you think I'll be ok there?
LionsDen wrote:I haven't worked with detached inventories or the players inventory much but I think I see something that might cause an issue, not sure if it is correct usage or not. The line below has a colon after suitcase. Shouldn't it just be suitcase?

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 drop_name == "suitcase:" then
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Oct 22, 2013 04:11

wcwyes wrote:What about the references to the item drop do you think I'll be ok there?
LionsDen wrote:I haven't worked with detached inventories or the players inventory much but I think I see something that might cause an issue, not sure if it is correct usage or not. The line below has a colon after suitcase. Shouldn't it just be suitcase?

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 drop_name == "suitcase:" then



I don't know. The only inventory work I have done has been with formspecs for some of my nodes. So I haven't really delved into item drops much beyond creating a node that when dug can drop different items randomly.
 

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

by wcwyes » Tue Oct 22, 2013 04:32

Sounds pretty cool, thanks for the help you did give
LionsDen wrote:
wcwyes wrote:What about the references to the item drop do you think I'll be ok there?
LionsDen wrote:I haven't worked with detached inventories or the players inventory much but I think I see something that might cause an issue, not sure if it is correct usage or not. The line below has a colon after suitcase. Shouldn't it just be suitcase?

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 drop_name == "suitcase:" then



I don't know. The only inventory work I have done has been with formspecs for some of my nodes. So I haven't really delved into item drops much beyond creating a node that when dug can drop different items randomly.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Oct 22, 2013 17:19

wcwyes wrote:Sounds pretty cool, thanks for the help you did give


Your welcome, wish I could have helped more though. Hope that you get it figured out.
 

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

by wcwyes » Wed Oct 23, 2013 00:46

fairiestoy wrote:Not to be rude, but did you ever inserted any debug prints in order to find out what your script is doing? I suggest you put this in, because i think its the problem:



any other ideas?
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 pos = minetest.get_pointed_thing_position(pointed_thing, under)
    local node = minetest.env:get_node(pos)
    local node_name = node.name
    local drop_name == minetest.registered_nodes[node_name].drop
    if string.match(drop_name, "suitcase:") then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                local player_inv = user:get_inventory()
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end
 

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

by wcwyes » Thu Oct 24, 2013 03:02

I think your debug syntax is wrong because I tried entering something I know is working and it still doesn't return anything. I know my string.match is working which means I should be able to return drop_name. but it doesn't return.I don't know much about debug so maybe I'm wrong.
fairiestoy wrote:Not to be rude, but did you ever inserted any debug prints in order to find out what your script is doing? I suggest you put this in, because i think its the problem:

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 drop_name == "suitcase:" then
        local bag_list = minetest.get_inventory({type='detached', name=user:get_player_name()..'_bags'})
        if bag_list then
            local bag1_inv = bag_list:get_stack('bag1', 1)
            print( 'Checking if the type of bag1_inv: ', type( bag1_inv ) ) -- <<< inserted this line
            if bag1_inv then
                bag_list:add_item('bag1', bag1_inv)
                player_inv:add_item('bag1', {name=drop_name})
            end
        end
    end
end


I would bet it returns nil

EDIT:I got this part working I think the rest should be pie, thanks for the help you did give.
Last edited by wcwyes on Thu Oct 24, 2013 03:19, edited 1 time in total.
 

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

by wcwyes » Thu Oct 31, 2013 18:19

 

Previous

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 3 guests

cron