Is there a method for getting number of item stacks?
- AccidentallyRhine
- Member
- Posts: 252
- Joined: Sun Aug 02, 2015 05:43
Is there a method for getting number of item stacks?
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.
- 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?
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)?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.
Believe in people and you don't need to believe anything else.
- AccidentallyRhine
- Member
- Posts: 252
- Joined: Sun Aug 02, 2015 05:43
Re: Is there a method for getting number of item stacks?
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?
So get_list() returns an array? an integer?
- rubenwardy
- Moderator
- Posts: 6978
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
- AccidentallyRhine
- Member
- Posts: 252
- Joined: Sun Aug 02, 2015 05:43
Re: Is there a method for getting number of item stacks?
I'm probably horribly misunderstanding things but this is the snippet I've been fighting:
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.
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,
- 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?
listname is a valid list. There are a few lists attached to the player, by default "main", "craft", and "craftpreview"
- AccidentallyRhine
- Member
- Posts: 252
- Joined: Sun Aug 02, 2015 05:43
Re: Is there a method for getting number of item stacks?
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.
Who is online
Users browsing this forum: shanish2 and 5 guests