ID:149834
 
I was wondering if there is any difference between these two loops:

for(var/mob/M in oview(1))
M << "you are a mob"

for(var/mob/M as mob in oview(1))
M << "you are a mob"

Doesn't the var/mob/M already make only mobs get looped through? It just seems a little redundant so I was wondering if there is actually a difference.
English wrote:
I was wondering if there is any difference between these two loops:

for(var/mob/M in oview(1))
M << "you are a mob"

for(var/mob/M as mob in oview(1))
M << "you are a mob"

Doesn't the var/mob/M already make only mobs get looped through? It just seems a little redundant so I was wondering if there is actually a difference.

Those two loops are the same, but these two produce different results:

for(var/mob/pc/M in oview(1))
M << "you are a pc mob"

for(var/mob/pc/M as mob in oview(1))
M << "you are a pc mob"

The first one filters all mob/pcs in oview and tells them that they are a pc mob. The second filters all mobs, /pc or not, and tries to treat them as a mob/pc. This can cause some unexpected results if you try to access pc variables, since the non-pcs won't have a value for the requested var.
In response to Shadowdarke
That makes sense :)

So now this brings us to the question, are there any good uses for "as mob","as obj", ect.?

I just can't think of a situation where you'd want to treat mobs as a mob of the wrong type...
In response to English
English wrote:
That makes sense :)

So now this brings us to the question, are there any good uses for "as mob","as obj", ect.?

I just can't think of a situation where you'd want to treat mobs as a mob of the wrong type...

It's useful when you combine filters. For instance, if you want all the turfs and mobs in an area but not the objs you could do something like this:

for(var/atom/A as mob|turf in Area)

I normally filter it myself if I need something like this, but it's an option.
In response to Shadowdarke
Ah, yes, I always forget about atom because I never really used it.

I probably won't use that method but it's always nice to have little tricks up your sleeves ;)

I usually store oview()(or whatever) in a list then remove whatever I don't want. Thanks again for the response