ID:261791
 
I can't seem to figure out what's wrong with this object grouping code I'm working on.
mob/Entered(var/obj/groupable/O)
for(var/obj/groupable/G in src)
if(istype(G.type,O.type))
O.amount += G.amount
del(G)
O.NewAmount(O)


There is the grouping part, and here is the other stuff...
obj
groupable
var/amount = 1
herb
icon = 'flowers.dmi'
icon_state = "herb"

verb/Get()
set src in oview(1)
src.loc = usr

proc/NewAmount(obj/groupable/O)
O.suffix = "x [O.amount]"


I've tried doing object grouping other ways but they've had a problem that made it so if I only picked up an item with an amount var of 1, it didn't count it, it only deleted the obj.

Well, anyways, the problem with this one is that it is not grouping them at all, it is just simply adding the objs to my contents, noting else. What could I do to ix it?
if(istype(G.type,O.type))

The first argument to istype() is an atom, not a type path. The second argument is a type path.

Also, I have a more versatile method for stacking objects right here, if you want to use it:
atom/movable
var/maxStackSize = 1
var/stack = 1
Move(atom/newLoc)
if(maxStackSize > stack)
for(var/atom/movable/M in newLoc.contents)
if(M.type == src.type)
while(M.stack < M.maxStackSize)
M.stack++
del(src)
Update()
..()
Del()
stack--
if(stack < 1)
..()
Update()
proc
Update()
if(maxStackSize < 1)
suffix = stack


Stackable objects just have their maxStackSize set higher than 1. You can remove one item from a stack by just deleting it, which will remove a single item from a stack. A recursive loop would be required to remove all the items in the stack.
Nevermind that question, I figured out the problem. Which was in my Get verb. I found out by reading the help files that <code>Entered()</code> is only called when an object has entered a contents list through <code>Move()</code>. I was using <code>src.loc = usr</code> which wasn't calling the grouping part. After realizing that and polishing up the grouping part of the code, It now works.

Resonating Light