ID:143493
 
Code:
mob
Del()
var/obj/Gold/G=new(loc)
G.amount=rand(0,2)
if(!G.amount)
del(G)
else
..()

obj
Gold
icon='Items.dmi'
icon_state="gold"
var
amount
verb
Get()
set category=null
set src in view(1)
usr<<"You picked up [amount] gold!"
src.Move(usr)
src.suffix="[amount]"
usr.gold+=amount
del(src)
Drop()
set category=null
set src in usr
src.Move(usr.loc)
usr<<"You drop [amount] [src]!"


Problem description: I've been getting worse and worse with my coding =/. When I try getting the gold, it doesn't go to my inventory. Whats wrong with it?

It's going into your inventory, it's just not staying there long because you're deleting it straight after the amount of gold is added to your current gold.
In response to DarkView
That can't be the problem because it only deletes the gold if the amount equals to 0. Even if that wasn't true, I took it out and tried playing it but it still didn't add the gold to my inventory.
In response to DarkD3vil666
Not really. Look at the last line of the Get() verb:
del(src)
:O!!!

In addition... in mob/Del()... if the amount is 0, the gold will be deleted but the deleted mob will still remain there because you haven't called the parent procedure ..() for that situation.
In response to GhostAnime
Oh, well that was stupid. Just for the sake of me not wasting like 15 minutes, can someone show me how to fix this: Every time I get gold now, it adds to the second slot. How would I do it if I already have gold in my inventory, for example 5, the next time I get more gold it adds to the 5 gold I already have. As you can see, I use the suffix to show how much gold I have.
In response to DarkD3vil666
You can try modifying mob/Entered() to see if it already exists or not using locate().

http://members.byond.com/GhostAnime/files/ Inventory_4.0_src.zip

That demo (which was showing how to use Grids in 4.0) uses a stacking system. It should help you understand what I mean by the above (like any other demo, this could be vastly improved on but made for demonstration purposes).