ID:165153
 
okay, so i've finally figured out how to make my inventory and i can put things in it, but how could i "stack" the objects, so if there's more than one of the same thing, they collect in one pile in the inventory?
I'd try and explain it directly but I'm about to go and have a shower (mental image'd!), so here's some links:

http://www.byondscape.com/ascape.dmb/LummoxJR.2005-0506/
(near the end of the article Lummox gives an example of item stacking)

http://developer.byond.com/hub/YMIHere/ItemStacking

http://developer.byond.com/hub/Buzzyboy/ItemStacking
In response to Elation
obj
var/count = 0 // 0 means not groupable; 1+ is groupable
proc/Update()
if(count)
// change suffix
suffix = (count>1) ? "[count]x" : null
// consider changing name to a plural here too

// tell if two items are alike
proc/IsAlike(obj/O)
if(!O || type != O.type || !count || !O.count || \
contents.len || O.contents.len) return 0
for(var/V in vars)
if(vars[V] != O.vars[V])
if(V in builtin) continue
return 0
return 1

// return the new obj in case it combines with another one
proc/MoveTo(atom/container)
if(count)
for(var/obj/O in container)
if(O != src && O.IsAlike(src))
O.count += count
O.Update()
loc = null // let this auto-delete
return O
loc = container
return src

// split off an obj and return the new one
proc/Split(n)
if(!count || n >= count || contents.len) return src
if(n <= 0) return null
count -= n
Update()
var/obj/O = new type(loc)
for(var/V in vars)
if(vars[V] != initial(vars[V]))
if(V in builtin) continue
// copy non-tmp lists
if(issaved(V) && istype(vars[V], /list))
var/list/L = vars[V]
O.vars[V] = L.Copy()
else O.vars[V] = vars[V]
O.count = n
O.Update()
return O

i gave gold coins a count=1 but they didn't stack. that doesn't work. i'll try the other two.
Ah! that third one seems to work, thanks, i'll just play around with that and see what happens. :)
In response to Adam753
obj/var
name1
amount
feather
name="Feather"
name1="Feather"
icon='Chicken.dmi'
icon_state="feather"
amount=1
verb
Get()
set src in oview(1)
var/counter=0
for(var/obj/feather/F in usr.contents)
counter+=1
if(counter<=0)
Move(usr)
else
for(var/obj/feather/F in usr.contents)
F.amount+=src.amount
F.Checkamount()
del(src)
Drop()
var/dropno = input("Drop how many Feathers?","Drop",) as num
if(dropno<=0)
return
for(var/obj/feather/F in usr.contents)
if(dropno>F.amount)
usr<<"<font size=1>You don't have that many feathers.</font>"
return
else
F.amount-=dropno
usr << "<font size=1>You drop [dropno] feathers.</font>"
F.Checkamount()
var/obj/feather/O = new(usr.loc)//<---Is this right now?
O.amount=dropno
O.Checkamount()
if(F.amount<=0)
del(F)
return

I find this way to be far less complicated :|



------------EDIT------------
I forgot to include the CheckAmount proc.. but I've been told im typecasting wrong. I dont know what that means o_O
So yeah... @_@
In response to CuriousNeptune
Young Padawan, comes a time in your life where you must decide between what is easy and what is right!
In response to CuriousNeptune
Problem is I wouldn't recommend someone to use that code snippet until you sort out stuff like this:

                    var/O = new /obj/feather(usr.loc)
O:amount=dropno
O:Checkamount()


If <code>O</code> is obviously going to be of type <codee>obj/feather</code> then it should be typecasted as such. Not only were you using : when you shouldn't but the solution was staring you straight in the face (as you've typecasted correctly elsewhere!).
In response to Adam753
Lummox' code works just fine; As the article mentions, you need to make sure to call the procs in the right places.