Page 1 of 1

adding items to inventory...or not

PostPosted: Wed Dec 02, 2015 05:56
by tbillion
i copy and pasted this code from
http://rubenwardy.com/minetest_modding_book/chapters/inventories.html


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 = ItemStack("default:coal_lump 99")
 local leftover = ninv:add_item("main", stack)


however it doesnt work but this code in a function...
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
setstackcount = function(pos, invin, name, count)
   local inv = minetest.get_meta(pos):get_inventory()
   local found = tbmroad.getstackcount(pos, name) + count
   local numberofstacks = math.floor(found / 99)
   local laststacksize = found % 99
   local h = 0
   for h = 1, numberofstacks do
      inv:add_item(invin, name.." 99")
   end
   inv:add_item(invin, name.." "..laststacksize)
end


does work...i have been staring at it now for a few hours and at the root of things i see no difference .. so why does the first one not work and the second one does?

Re: adding items to inventory...or not

PostPosted: Wed Dec 02, 2015 07:06
by kaeza
Start by defining "doesn't work".

Does it cause an error? Hasn't the expected result? Formats your hard drive? Other?

Re: adding items to inventory...or not

PostPosted: Wed Dec 02, 2015 17:24
by kaadmy
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 leftover = ninv:add_item("main", stack)

ninv isn't defined, is that the problem?

Re: adding items to inventory...or not

PostPosted: Wed Dec 02, 2015 22:05
by tbillion
if we are going by error then there isnt a problem, the first code doesnt add an item to the inventory. and ninv is defined in the code so that is not the error.

the function was in the mod when i got a hold of it . in fact it is the only surviving code from the original mod. this is because up until this point i didnt really care about managing the inventory, now i am to the point where i need to add and subtract things from inventories and move objects from one inventory to another.