ID:1029688
 
(See the best response by Speedro.)
Problem description: I feel extremely stupid right now, but after at least three hours of trying literally at least 25+ different things and making this code have some weirdness I just plain cannot get item stacking to work right with banking.

I'm using Evi of Au's Item Stacking library because it was simpler and easier than any methods I thought of and I was in a hurry. So much for quick, though, eh? Anyway, the problem seems to be that no matter what I do the item within the banks contents does not increase, which seems to be the cause of the worse problem; I can't withdraw more than one item. It always registers as one item with no contents within it.

All the related code that you cannot find in the library is located below, but please do excuse how ugly it is. I really tore it up just getting it to work this much, and I haven't cleaned it up yet since the feature doesn't even work right. Plus this is not my strong suit since it somewhat involves lists.

Code:
                    var/obj/D = input("What would you like to deposit?","Deposit Item") in depositable
if(D.stackable == 1)
var/obj/citem
for(var/obj/i in usr.contents)
if(i.type == D.type)
citem = i
if(citem.contents.len > 0)
usr.DeleteItems(citem)
else
usr.contents -= D
D.suffix = "x1"
var/obj/citem2
for(var/obj/i2 in usr.bankeditems)
if(i2.name == D.name)
citem2 = i2
if(citem2 && citem2.name == D.name)
citem2.contents += D
citem2.suffix = "x[citem2.contents.len+1]"
world << "Citem contents = [citem2.contents.len+1]"
world << "Citem2 exists."
else
usr.bankeditems += D
D.suffix = "x1"
world << "Citem2 does not exist."
src.talkedto = 0
else
usr.contents -= D
usr.bankeditems += D
usr << "<b>Very well, you have deposited your [D.name]. Have a nice day.</b>"
src.talkedto = 0

withdraw_item()
set name = "Withdraw Item"
set category = null
set src in oview(1)
if(src.talkedto == 1)
return
src.talkedto = 1
if(usr.bankeditems.len > 0)
var/obj/W = input("What would you like to withdraw?","Withdraw Item") in usr.bankeditems
if(W.stackable == 1)
var/obj/citem
for(var/obj/i in usr.bankeditems)
if(i.type == W.type)
citem = i
if(citem && citem.contents.len > 0)
citem.contents -= W
usr.AddItems(W)
world << "Citem exists."
usr << "<b>Very well, you have withdrawn your [W.name]. Have a nice day.</b>"
else
usr.AddItems(W)
usr.bankeditems -= W
world << "Citem does not exist."
else
usr << "<b>Very well, you have withdrawn your [W.name]. Have a nice day.</b>"
usr.contents += W
usr.bankeditems -= W
src.talkedto = 0
else
usr << "<b>You don't have anything banked!</b>"
src.talkedto = 0




Best response
Sorry I don't have a lot of time, but here's how I generally handle stacking:

mob
var
list/mybank = list()
obj
verb
deposit()
set src in usr
loc = null
for(var/o in usr.mybank) //check contents of your bank
if(!usr.mybank["[name]"]) //if this object isnt a list in your bank
usr.mybank["[name]"] = list() //make it
usr.mybank["[name]"] += src //add this object to the bank list for that item


Then you can just search the contents of each individual item, then loop through those contents to access the amount of a particular object, and just remove them from the same object list as it's name. Hope this makes sense!
Thank you so much for your response. It did make a lot of sense, and presented an idea or two I hadn't thought of. I ended up doing things a bit differently, but your method got me thinking on the right track and ultimately lead to me programming my own system.

I'm now no longer using the Evi of Au Library, and the item banking seems to be working well. It also all uses much less lengthy, and much better code in my opinion. I can't believe how much trouble it turned out to be, but I am especially pleased with this outcome.
In response to Speedro
obj.name is already text. There's no need to embed it into text. Your for() loop is also completely unnecessary.
if(!usr.mybank[name])
user.mybank[name] = list()
usr.mybank[name] += src
I shall now optimize my own code at some point. I wonder how much this will reduce system usage?

EDIT: Nevermind, the way I had it was relevant for the block of code I was using. I copy/pasted and altered for the example, but in my actual code block the for loop is necessary.