adding items to inventory...or not

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

adding items to inventory...or not

by tbillion » Wed Dec 02, 2015 05:56

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?
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: adding items to inventory...or not

by kaeza » Wed Dec 02, 2015 07:06

Start by defining "doesn't work".

Does it cause an error? Hasn't the expected result? Formats your hard drive? Other?
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
kaadmy
Member
 
Posts: 627
Joined: Thu Aug 27, 2015 23:07
GitHub: kaadmy
IRC: KaadmY
In-game: KaadmY kaadmy NeD

Re: adding items to inventory...or not

by kaadmy » Wed Dec 02, 2015 17:24

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?
Never paint white stripes on roads near Zebra crossings.
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: adding items to inventory...or not

by tbillion » Wed Dec 02, 2015 22:05

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.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron