ID:1338909
 
(See the best response by Jittai.)
obj/item
var
canDye = 0
vairies = 0
stack = 0
stackable = 0
onFloor = 0
wealth
stackable = 1
name = "Gold"
icon = 'wealth.dmi'
icon_state = "tens"

mob/proc
addItem(obj/item/i)
if(i.stackable && i.stack > -1)
var/obj/item/z = locate(i.type) in src
if(z)
z.stack += i.stack
if(istype(i, /obj/item/wealth))wealth(z)
del i
return

i.Move(src)
if(istype(i, /obj/item/wealth))wealth(i)

wealth(obj/item/i)
if(istype(i, /obj/item/wealth))
if(i.stack < 1000) i.icon_state = "tens"
else if(i.stack >= 1000 && i.stack < 10000) i.icon_state = "1k"
else if(i.stack >= 10000 && i.stack < 100000)i.icon_state = "10k"
else if(i.stack >= 100000 && i.stack < 1000000)i.icon_state = "100k"
else i.icon_state = "1m"
i.suffix = "x[Comma(i.stack)]"

bank(obj/item/i)
if(i.stackable && i.stack > -1)
var/t = input("How many [i] do you wish to deposit","Deposit") as num|null
if(t < 1 || t == null) src << "<b>Info:</b> You deposited nothing."
else if(t > i.stack) src << "<b>Info:</b> You don't have that much of [i]."
else
i.stack -= t
if(i in bank)
i.stack += t
src << "happpening"
else bank.Add(i)
if(i.stack < 1) contents.Remove(i)


else bank.Add(i)
bankUpdate()

bankUpdate(var/i = 0)
set background = 1
if(banking)
winset(src,"miscGrid",null)
for(var/obj/item/t in bank)
if(istype(t, /obj/item/wealth)) wealth(t)
src << "[t]: [t.stack]"
src << output(t, "miscGrid:[++i]")
winset(src, "miscGrid", {"cells = "1x[i]""})


Problem description: It's probably an easy fix but I just can't seem to get it to work. I am trying to add a stackable object into a list.

Bump
"What is wrong with it" is usually a good start, I don't really want to scan the whole code for what may be wrong.

Most people skim through these and try to help where they can.
In response to Jittai
So if the item is "Stackable" and it's already inside the bank list, I can't seem to deposit more of that item into the bank. My problem is that I can't increase the stack of that specific item.

This is the problem right here.
if(i in bank)
i.stack += t
src << "happpening"
Best response
I don't see bank being defined here is it a list set to something?

Also finding "i" in bank is looking for an EXACT item. What you want to do is look for i.type and perhaps a few other things depending on your game.

Unless I'm misunderstanding what you're trying to do, this seems a little overcomplicated.

Create your object, and give it a variable to keep track of the value. Let's also add in a proc to change the value variable of this object, in this proc, you can also add your checks to change it's icon state.
obj/wealth
name="gold"
icon='wealth.dmi'
icon_state="tens"

var/value //The value of your wealth.

proc/changeValue(amt)
value += amt
//change icon state based in value here

Now we need to give the player two variables to represent their bank, and money on hand. After the player has logged in and loaded, we will check if these variables need to be initialized. If so, lets give the player 100 gold to start off with.
mob
var/obj/wealth/bank //banked money
var/obj/wealth/wealth //money on hand

Login()
..()
//load character stuff
//create these objects if needed
if(!bank)
bank = new
if(!wealth)
wealth = new
//give the player 100 gold to start with
wealth.changeValue(100)

Next up is the verb to bank some money. Remember, to subtract from the value, just put a negative number into the changeValue proc.
mob         
verb/Bank(var/n as num)
if(wealth.value >= n)
//decrease gold by entering -n
//increase gold by entering n
wealth.changeValue(-n)
bank.changeValue(n)
src << "You banked [n] [wealth]."
else
src << "Not enough [wealth]."
//Update Grid stuff
Danny, that doesn't handle item storage at all, he's trying to have a bank which can contain items AND money.
I don't even think he has a money code, he just has money acting as an item and using the stacking proc. But his issue is simply a misunderstanding of if(i in bank).
@Jittai: This is how my bank list is defined.
mob/var/list/bank = list()


@Danny: Thanks for the response but that's not what I am trying to do.
obj/item
var
canDye = 0
vairies = 0
stack = 0//the amount of the stackable item basically.
stackable = 0//does this item stack?
onFloor = 0
wealth
stackable = 1
name = "Gold"
icon = 'wealth.dmi'
icon_state = "tens"

So There is Banker NPC. I Click on the npc. I choose to Deposit my items. A window pops up. My banking value is TRUE. I click on the Item inside in my contents(inventory) that I want to store. The items that I click are added into the "Bank" list and "bankUpdate" proc activates. For stackable items I have to decide how much I want to store.

Alright. So all of that works until! I want to add more of a stackable item that's inside the "bank" list. The "how much you want to deposit" prompt still occurs but when I enter a value and hit ok, nothing happens to the item in my contents nor the item in the "Bank" list. Both of their stack values stay the same and I still get my "happening" debug.

@Rushnut: BINGO!
In response to Luchasi
As Jittai has said multiple times now (But you can give me your asker's pick because I'm sexier than him), you're using if(i in bank). i is already a defined refrence to another item, specifically one in your inventory, and since it's in your inventory it certainly isn't in the bank.

You need to be checking if there's anything of the same type of i in the bank, not if i itself is in the bank. There are numerous ways of handling this but you seem competent enough that I believe you'll manage it.
In response to Rushnut
I been at this for quite awhile but I cant seem to get it. I apologies for my incompetence.

I tired this
bank(obj/item/i)
if(i.stackable && i.stack > -1)
var/t = input("How many [i] do you wish to deposit","Deposit") as num|null
if(t < 1 || t == null) src << "<b>Info:</b> You deposited nothing."
else if(t > i.stack) src << "<b>Info:</b> You don't have that much of [i]."
else
i.stack -= t
for(var/obj/item/z in bank)
if(z.type == i.type)
z.stack += t
src << "happpening"

else bank += i
if(i.stack < 1) contents.Remove(i)


else bank.Add(i)
bankUpdate()

This doesn't work because I can't find a way to add "i" if "z.type == i.type" conditional statement proves to be false.

~Regards
If there;s only one of those types of items allowed in the bank then you could just use

var/obj/item/z == locate(i.type) in bank
if(z) z.stack += t
else bank += i


So you get the input right? If so try putting more debug messages like "happening" in each step, I like to number them "1" "2" "3" to pinpoint where the code is going wrong.

Also note removing i from contents doesn't delete that object and it still exists in null.
In response to Jittai

bank(obj/item/i)
if(i.stackable && i.stack > -1)
var/t = input("How many [i] do you wish to deposit","Deposit") as num|null
if(t < 1 || t == null) src << "<b>Info:</b> You deposited nothing."
else if(t > i.stack) src << "<b>Info:</b> You don't have that much of [i]."
else
i.stack -= t

var/obj/item/z = locate(i.type) in bank
if(z)
z.stack += t
src << "happening 2"
else
bank += i
src << "Happening 1"

if(i.stack < 1) del(i)


else bank.Add(i)
bankUpdate()


I came across that method at one point but I disregarded it because although "happening 2" still occurs, "z.stack += t" does not go through. "z.stack" never increases by t. I'm really stomped right now.
In response to Luchasi
Not precisely a fix to the problem you're observing but

                else 
bank += i
src << "Happening 1"

if(i.stack < 1) del(i)


This will delete the i even from the bank if the stack is < 1.
You should remove that delete statement all together.
Can you add more debug messages along the code?

Also if "happening 2" occurs then stack += t should be. Change "happening 2" to "zfound: [t] added, z.stack now [z.stack]" and tell me what it is reporting as?

And you should only be deleting 'i' in the case of there being a z and i's stack is less than 1. so put that if() del i under the if(z).
In response to Jittai
I'm not sure if this will help or not.
mob/verb
Free_Money()
var/obj/i = new/obj/item/wealth
i:stack = 1000
i:onFloor = 1

i.loc = locate(usr.x, usr.y-1, usr.z)

So I basically execute this verb, click on the object and it's added to my contents with the add_item proc I posted at the beginning of this thread.

Bank Proc again
bank(obj/item/i)
if(i.stackable && i.stack > -1)
var/t = input("How many [i] do you wish to deposit","Deposit") as num|null
if(t < 1 || t == null) src << "<b>Info:</b> You deposited nothing."
else if(t > i.stack) src << "<b>Info:</b> You don't have that much of [i]."
else
i.stack -= t

var/obj/item/z = locate(i.type) in bank
if(z)
src << "z.stack before t is added [z.stack]"
z.stack += t
src << "zfound: [t] added, z.stack now [z.stack]"
if(i.stack < 1) del(i)
else
bank += i
src << "Happening 1"


else bank.Add(i)
bankUpdate()


The Debugs.

"Happening 1 & i.stack is 700

z.stack before t is added 550

zfound: 150 added, z.stack now 700

z.stack before t is added 200

zfound: 500 added, z.stack now 700

z.stack before t is added 100

zfound: 600 added, z.stack now 700"

What's weird is that z.stack has the same stack value that "i"(in my contents) holds.
When you add i to the bank are you also removing it from your inventory?

Also your log in weird, only use the verb once, or did you only use it once?
EDIT: Forgot you wanted this to work with all items, updated.
    bank(obj/item/i)
if(i.stackable && i.stack > -1)
var/t = input("How many [i] do you wish to deposit","Deposit") as num|null
if(t < 1 || t == null) src << "<b>Info:</b> You deposited nothing."
else if(t > i.stack) src << "<b>Info:</b> You don't have that much of [i]."
else
var/obj/item/z = locate(i.type) in bank
if(z)
z.stack += t
i.stack -= t
if(i.stack < 1) del(i)
else
if(t==i.stack)
src.contents.Remove(i)
bank.Add(i)
else
var/obj/item/W = new i.type
W.stack = t
bank += W
i.stack -= t


else
src.contents.Remove(i)
bank.Add(i)
bankUpdate()

Deleted my last post, was a little hasty and there was a couple of errors.

The problem is that i should only be moved to the bank if you transfer the entire stack, otherwise you must create a new object and add that to the bank (assuming z doesn't exist). Also as Jittai said, you have to remove it from your inventory when you add the object into the bank.
@Jittai- thanks for all your help!
@Rushnut- you too man.
@Danny- It has been solved! thank you!

I will make sure to add you guys on my credit list.