var/list/Inventory = list()
world/New()
..()
var/item/Potion/P = new /item/Potion
var/item/Sword/S = new /item/Sword
Inventory += S
Inventory += P
Inventory += P
item
var/stackable = 0
Potion
stackable = 1
Sword
proc/OutputInventory()
var/list/items = list()
var/list/stackeditems = list()
for(var/item/O in Inventory)
if(stackeditems.Find(O))
stackeditems[O] += 1
continue
if(I.stackable)
stackeditems += O
stackeditems[O] = 1
else
items += O
for(var/i in items)
world << i
for(var/i in stackeditems)
var/i2 = stackeditems[i]
world << stackeditems[i2]
Problem description:I have an on-screen inventory system, and i programmed it to stack items and output the number of items of that type you have in your inventory. Almost exactly like above(I just removed a lot of the extra stuff I do, and without the on-screen part and such. This is the procedure). The problem is, anything I create after run-time, that is suppose to stack, Like "potion" for example, counts itself as a completely new item. Even if i make multiple copies of it. While on the other hand, the ones generated at New(), stack and work perfectly fine.
I have no idea at all as to why this is happening, Any help would be nice. Thanks.
> if(stackeditems.Find(O))
Think about what this line is actually searching for: an individual instance of an item, not a type! If you want to search a list for a specific type, you'll have to loop through it and manually check each item's type variable against the new item's.*
The reason the items created in world/New() work is because you're only creating one /item/Potion instance, and adding that same instance to the list twice.
* you can't use locate() here, see if you can figure out why ;)