Is there a method for getting number of item stacks?

Post Reply
User avatar
AccidentallyRhine
Member
Posts: 252
Joined: Sun Aug 02, 2015 05:43

Is there a method for getting number of item stacks?

by AccidentallyRhine » Post

Specifically dealing with node metadata, get_count() was close but I'm looking for the sum of itemstacks in a node, rather than the sum of items in a stack.

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: Is there a method for getting number of item stacks?

by duane » Post

AccidentallyRhine wrote:Specifically dealing with node metadata, get_count() was close but I'm looking for the sum of itemstacks in a node, rather than the sum of items in a stack.
Wouldn't that be the count (#foo) of InvRef:get_list(listname), or do you want the total count of all objects of every type (which would just require looping through the table and getting the get_count of each)?
Believe in people and you don't need to believe anything else.

User avatar
AccidentallyRhine
Member
Posts: 252
Joined: Sun Aug 02, 2015 05:43

Re: Is there a method for getting number of item stacks?

by AccidentallyRhine » Post

Just getting the count of stacks regardless of what they are or how many items they hold. The Invref page could really use some examples.

So get_list() returns an array? an integer?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Is there a method for getting number of item stacks?

by rubenwardy » Post

Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
AccidentallyRhine
Member
Posts: 252
Joined: Sun Aug 02, 2015 05:43

Re: Is there a method for getting number of item stacks?

by AccidentallyRhine » Post

I'm probably horribly misunderstanding things but this is the snippet I've been fighting:

Code: Select all

	allow_metadata_inventory_put = function(pos, listname, index, stack, player)
		if listname=="offer" then
			local meta=minetest.get_meta(pos)
			local inv=meta:get_inventory()
			if inv:get_size("listname") <= 3 then
				return stack:get_count()
			else
				mod.formspecs.dosomething.open(player, pos, true)
			end
		end
		return 0
	end,
The line with the less than/equal to operator get_size() returns always 0. Basically am just trying to reject item input after the node already has 3 stacks of anything.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Is there a method for getting number of item stacks?

by rubenwardy » Post

listname is a valid list. There are a few lists attached to the player, by default "main", "craft", and "craftpreview"
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
AccidentallyRhine
Member
Posts: 252
Joined: Sun Aug 02, 2015 05:43

Re: Is there a method for getting number of item stacks?

by AccidentallyRhine » Post

Thanks for the help rubenwardy. It would seem listname was referring to an empty list. The mod I'm tinkering on appears to store item stacks outside of the standard inventory convention so I've fallen back to using pairs() to iterate over the stacks and count them. What a mess.

Post Reply

Who is online

Users browsing this forum: shanish2 and 5 guests