adding items to inventory...or not

Post Reply
User avatar
tbillion
Member
Posts: 190
Joined: Wed Apr 03, 2013 16:07
Location: 38381, US, TN, Toone
Contact:

adding items to inventory...or not

by tbillion » Post

i copy and pasted this code from

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...

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
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

Re: adding items to inventory...or not

by kaeza » Post

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

User avatar
kaadmy
Member
Posts: 706
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 » Post

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.

Pixture

User avatar
tbillion
Member
Posts: 190
Joined: Wed Apr 03, 2013 16:07
Location: 38381, US, TN, Toone
Contact:

Re: adding items to inventory...or not

by tbillion » Post

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests