Page 1 of 1

how to cycle backpack slots

Posted: Thu Mar 08, 2012 11:09 pm
by Rickster
i read about this way to cycle all inventory slots

Code: Select all

for slot, item in pairs(inventory.BagSlot) do
this cycles through all your item shop, transmutor and backpack slots.

i am looking for loop that only cycles through existing backpack slots. so if someone only has backpack slot one and two, it shall only cycle these.

someone has an idea, how to do that?

thanx
ric

Re: how to cycle backpack slots

Posted: Thu Mar 08, 2012 11:20 pm
by rock5
Well the bags are slot 61 to 240. There is nowhere stored which bags are available but the slots themself are marked available. Usually I would do it like this (assuming your not looking for empty slots)

Code: Select all

for slot = 61, 240 do
    if (not slot.Empty) and slot.Available then

Re: how to cycle backpack slots

Posted: Thu Mar 08, 2012 11:48 pm
by Rickster
i would like to get an object to work with, for example
itemName = item.Name

so how do i get "item" as an object in the loop?

[edit]
got it :)

Code: Select all

		for slot = 61, 240 do
			if (not inventory.BagSlot[slot].Empty) and inventory.BagSlot[slot].Available then
				item = inventory.BagSlot[slot]
				printf("%s. %s\n", slot, item.Name);
			end;
		end;

Re: how to cycle backpack slots

Posted: Fri Mar 09, 2012 3:37 am
by rock5
Sorry, I did it wrong. I meant to say I would do it like this.

Code: Select all

local item
for slot = 61, 240 do
    item = inventory.BagSlot[slot]
    if (not item.Empty) and item.Available then
So a better way of doing what you said would be

Code: Select all

		local item
		for slot = 61, 240 do
			item = inventory.BagSlot[slot]
			if (not item.Empty) and item.Available then
				printf("%s. %s\n", slot, item.Name);
			end;
		end;