ID:141511
 
Code:
mob/proc/checkObstruction()
for(var/turf/O in get_step(usr,dir))
if(O.density)
usr << output("The turf: [O] to your [usr.dir] is dense","output1")
else
usr << output("The turf: [O] to your [usr.dir] is not dense","output1")


Problem description:
I want to check to see if a turf in the direction I am facing is dense, however the for loop does not initialize. Am I doing it wrong?
ArcaneDragonX wrote:
Code:
> mob/proc/checkObstruction()
> for(var/turf/O in get_step(usr,dir))
> if(O.density)
> usr << output("The turf: [O] to your [usr.dir] is dense","output1")
> else
> usr << output("The turf: [O] to your [usr.dir] is not dense","output1")
>

Problem description:
I want to check to see if a turf in the direction I am facing is dense, however the for loop does not initialize. Am I doing it wrong?

Error: Dont use usr in a proc, use src.
that might be all thats wrong.
mob/proc/CheckObstruction()
//Store the turf in that direction in a variable.
var/turf/t = get_step(src, dir) //Don't use usr in procs.
if(t)
//If t exists, return its density. You may want to
//write a proc that has the turf check that there
//is nothing dense *on* it, and return the value of
//that proc.
return t.density

//If there isn't a turf, it's presumably the edge of the
//map, which is, essentially, an obstruction. :P
return 1
In response to Popisfizzy
Good call, exactly what I was looking for. Thanks!
This is a common issue arising from not fully understanding the statements used. If you look up get_step(), you'll see it returns a turf (if it finds one), and if you look up for()-list, you'll see it loops through a container (either a list or an object that its contents list will be used) looking for stuff in it, potentially looking for a given type of objects (in your code, you're looking for turf objects). This doesn't go together, as you're trying to loop through other turfs in the contents of the turf get_step() returns. There's really no need to loop or look through any list, as get_step() already gives you the turf you want directly.