ID:1884135
 
Descriptive Problem Summary:
I have a for loop that loops through usr.contents for all atoms of type componentType. Seems simple but when the loop is done componentType is null.

Code Snippet (if applicable) to Reproduce Problem:
obj
Knife
icon_state = "Knife"
components = list(/obj/Blade = 1, /obj/Handle = 1)

    // Check for all components needed
for(var/componentType in components)

world << componentType

// How many of these components are in usr contents?
var/amountFound = 0
for(componentType in usr.contents)
amountFound ++

world << componentType


Expected Results:

The output should be:

/obj/blade
/obj/blade
/obj/handle
/obj/handle


Actual Results:

The output is:

/obj/blade
(blank line) (null)
/obj/handle
(blank line) (null)

I'm sure it's null because I checked using if(componentType == null) and it came back yes. Plus null is outputted of course as a blank line.
Kaiochao resolved issue (Not a bug)
In response to Kaiochao
Why is this not a bug? Maybe I'm just tired but I can't seem to work out for the life of me why this is happening.
In response to Kaiochao
You're using a predefined variable as the iteration variable of the for() loop. This overwrites the variable with all the values being iterated over. You'll only get a non-null value in that variable if you "break" the loop.
var n = "pie"
for(n in 1 to 10) world << n

What you tried to do is loop through every object of the type specified in componentType. Although a more flexible type filter would be nice, that's not the way to do it. Instead, you might do something like this:
proc/count(stuff[], type)
. = 0
for(var/thing in stuff)
if(istype(thing, type))
.++
In response to Kaiochao
I see what you mean. Thanks. Yeah it's a case of verbally it sounds correct but mechanically that's not exactly what's going on.