ID:2125477
 
(See the best response by Kaiochao.)
Code:
if( locate(type1) in loc || locate(type2) in loc || locate(type3) in loc )
//Do some stuff.

var/found = false
for( var/obj/O in loc )
if( istype(O,type1) || istype(O,type2) || istype(O,type3) )
found = true
break


Which of the above examples would be best?

I was wondering how locate() works in DreamMaker, and if there's a reason I should or shouldn't use one or the other.


This is especially important for operations that occur often, like if a fire object should be extinguish, if water happens to be on the same tile.
Best response
The first one is definitely the best. In the best case, you call locate() once. In the worst case, you call locate() 3 times.

For the second one, in the best case, you call istype() once. In the worst case... infinite calls to istype().

Beware of order of operations when using the "in" operator. It has oddly low precedence, so it's best to surround "A in B" expressions in parentheses.
(locate(type1) in loc) || (locate(type2) in loc) || (locate(type3) in loc)