ID:146872
 
I'm trying to get a proc that takes a mob and calls a function on every /atom in the tile next to him. (In the direction he faces. If he's facing down, then the tile below him, etc.)

So far I've got: (this is in a proc, btw. M is of /mob, and is the person in question.)
var/atom/A
// ...other code here...
for(A in locate(get_step(M, M.dir)))
A.btnA(M)


A.btnA(M), under normal conditions, would, by default, do nothing. Currently it world << "Yahoo." simply to let me know it's working. (Which it's not.)
The point is, A.btnA(M) would get overridden by a subclass, and then actually do something worthwhile.

Thanks for any help!
(I think I've fried my brain on too much BYOND coding...)
Nova2000 wrote:
I'm trying to get a proc that takes a mob and calls a function on every /atom in the tile next to him. (In the direction he faces. If he's facing down, then the tile below him, etc.)

So far I've got: (this is in a proc, btw. M is of /mob, and is the person in question.)
var/atom/A
> // ...other code here...
> for(A in locate(get_step(M, M.dir)))
> A.btnA(M)
>


A.btnA(M), under normal conditions, would, by default, do nothing. Currently it world << "Yahoo." simply to let me know it's working. (Which it's not.)
The point is, A.btnA(M) would get overridden by a subclass, and then actually do something worthwhile.

Thanks for any help!
(I think I've fried my brain on too much BYOND coding...)

You do not need to use locate(get_step()). According to the DM Reference, locate() and get_step() return a turf. You do not need the locate.

for(var/atom/A in get_step(src,src.dir)) // returns all atoms in the CONTENTS of the turf
...


So if you wanted an area's proc to be called, that wouldn't work, since a turf is in the area's contents, not vice versa. You'd have to call the area seperatly. And if you'd want to call the turf too, you'd have to call that seperatly also.

To call the turf's proc and the area's proc, we can do this.
var/turf/T = get_step(src,src.dir) // the turf in front of the person
T.thatproc()
var/area/A = T.loc // all turf's locs are areas, guarenteed!
A.thatproc()


Hope I've been a help.

~~> Dragon Lord
In response to Unknown Person (#1)
Thanks, the info helped a lot! (Works perfectly now.)