ID:141514
 
Code:
for(var/mob/M in get_step(usr,dir))


Problem description:
Is there any more efficient way to find mob infront me?
Not really. But there's no need for one.
Depends if you want to find a single mob or all the mobs or all mobs within a specific parameter.
In response to Spunky_Girl (#2)
Single, as there shouldn't be more than one
In response to Ripiz (#3)
You can then use locate()'s version of finding a specific object type within a container (needless to say, look it up); it just returns the first one it finds in it (there could be additional ones). It's equivalent to a for() loop like this:
for(var/object_type/V in Container)
Do_Stuff
break //only process the first found object

// ==
var/defined_type/V = locate(object_type) in Container


The efficiency increase is there, although not groundbreaking and this topic is pretty weird in itself; if you have some apparent slowdowns in your code, the problem is not there (ie, the for() line), but in the loop body (or elsewhere). You may also want to consider that it's feasibly possible for multiple mobs to occupy the same turf (though you may still prefer to simply process through one anyway).
In response to Kaioken (#4)
I just was bit too lazy to code
for(var/mob/M in get_step())
//code
break

But thanks for reply, I'll use that now