Page 1 of 1

inventory:itemTotalCount() question

Posted: Fri Feb 14, 2014 9:54 am
by noobbotter
I have all 6 inventory bags unlocked/available but in one of my functions, I want to get the available space of only the first 4 bags. Would this work?

Code: Select all

slotsavailable = inventory:itemTotalCount(0,{"bag1","bag2","bag3","bag4"})
if not, then maybe I should do something like:

Code: Select all

slotsavailable = inventory:itemTotalCount(0,"bag1")
slotsavailable = slotsavailable + inventory:itemTotalCount(0,"bag2")
slotsavailable = slotsavailable + inventory:itemTotalCount(0,"bag3")
slotsavailable = slotsavailable + inventory:itemTotalCount(0,"bag4")
and then my other choice would be to do

Code: Select all

slotsavailable = 0
for slot = 61, 180 do
		local item = inventory.BagSlot[slot]
		if item.ID == 0 then
			slotsavailable = slotsavailable + 1
		end
	end
So what would be the best option for me? Thanks.

Re: inventory:itemTotalCount() question

Posted: Fri Feb 14, 2014 11:11 am
by rock5
The first option I would say doesn't work. The second and third look like they would. I think the second would be simpler and it also updates the slot info. Whereas the third does not, although you could add an "item:update()" if you wanted to.

Re: inventory:itemTotalCount() question

Posted: Fri Feb 14, 2014 11:55 am
by noobbotter
Thanks for the feedback. After looking at how I was going to implement it, I decided to make a separate variable for how many slots I would use so I could easily change it so I'm going to be doing this:

Code: Select all

bagstouse = 4 	<!-- We will use this many bags for this script. I.e., with default of 4, it will use bags 1 thru 4 (slots 61 thru 180. -->)
	endslot = 0 -- establish the variable

	function setBagSlots()
		if bagstouse == nil then
			bagstouse = 4
		end
		
		if bagstouse == 1 then
			endslot = 90
		elseif bagstouse == 2 then
			endslot = 120
		elseif bagstouse == 3 then
			endslot = 150
		elseif bagstouse == 4 then
			endslot = 180
		elseif bagstouse == 5 then
			endslot = 210
		elseif bagstouse == 6 then
			endslot = 240
		end
	end

	setBagSlots()
   inventory:update()
	for slot = 61, endslot do
	   if item.ID == 0 then
			slotsavailable = slotsavailable + 1
		end
   end
-- of course I have a lot more code than this that executes within the functions and in the for statement. I just shortened it down for the applicable part that I had a question about. Doing it this way, I can use the endslot variable for my mailing functions as well. so everything I do within this waypoint will apply only to the bags I want to use, so that I can be safe that I won't accidentally send any good items I might have in bag 5 or 6. I'm updating my belt and fusion stone buying and sending script so it will look at how many equipment I currently have, look at my empty slots, look at how many characters I have to send to, and calculate a number of items to buy, then buy and send those proper amounts. In addition to that, It will start with a menu where I choose which group I want to send to, or I select the last option which is "All Groups" in which case it will go through the whole process for each group I have (currently I have 3 groups - 1 with 11 characters, and 2 groups with 16 each.) I've almost got the whole thing working. Hopefully tonight will be the magic night where it'll run through without errors.

Re: inventory:itemTotalCount() question

Posted: Fri Feb 14, 2014 8:00 pm
by rock5
Maybe

Code: Select all

endslot = 60 + 30 * bagstouse

Re: inventory:itemTotalCount() question

Posted: Mon Feb 17, 2014 2:50 pm
by noobbotter
Don't know how I didn't see that. Thanks again.