ID:2571227
 
            if(src.stackable)
var/obj/object = locate(text2path("[src.type]")) in M.contents
if(object)
if(object.amount>=object.a_max) return
object.amount++
...(rest of code)


CURRENTLY:

Checks if obj is stackable.
Locates object in M.contents.
IF obj, then; IF amount < obj max amount, code runs correctly.


HOW TO:

With this current system, the check simply haults if(object.amount>=object.a_max) returns 1.

I want the the proc to check if there is another object inside M.contents that is also the same type
as the original obj, then have that second object run the same if(object.amount>=object.a_max) as the original.


What is the best way to accomplish this without using nested-IF statements? If doing so, the proc would stop after only checking for two objects?
Repeating behavior implies some kind of loop. It's hard to tell what your code is actually trying to accomplish, but this might be a good starting point:
for(var/thing in M)
if(istype(thing, src))
var/obj/object = thing
if(object.amount < object.a_max)
object.amount++
I just wanted to point out, completely aside.

text2path("[src.type]")


Is 100% redundant. The type variable is always going to be a path when you're dealing with a datum. If it's not, you did something, very, very wrong. Surrounding it with quotation marks is what's turning it into a string.
In response to Nadrew
Nadrew wrote:
I just wanted to point out, completely aside.

> text2path("[src.type]")
>

Is 100% redundant. The type variable is always going to be a path when you're dealing with a datum. If it's not, you did something, very, very wrong. Surrounding it with quotation marks is what's turning it into a string.

So it should be simply (src.type)? That makes sense, actually.

Kaiochao wrote:
Repeating behavior implies some kind of loop. It's hard to tell what your code is actually trying to accomplish, but this might be a good starting point:
> for(var/thing in M)
> if(istype(thing, src))
> var/obj/object = thing
> if(object.amount < object.a_max)
> object.amount++
>


That's essentially my original code. With the code in OP; everything works as it should unless object.amount>=object.a_max.

Then the code simply returns. I'm attempting to find the next object in the mob's inventory instead of simply using if(object.amount>=object.a_max) return.

In response to Magicbeast20
The original code has no loop. The main point of my post was that a loop is needed. Also, my loop doesn't return after one iteration over a matching object, it continues to find more matches.
In response to Kaiochao
Kaiochao wrote:
The original code has no loop. The main point of my post was that a loop is needed. Also, my loop doesn't return after one iteration over a matching object, it continues to find more matches.

Gotcha. I’ll try it out. Thanks!