ID:261178
 
I have a proc to return a front list:

mob
var
list
front = ""
proc
front(var/item)
for(var/atom/A in front)
del(A)
switch(src.dir)
if(NORTH)
for(var/atom/A in locate(src.x,src.y+item,src.z))
front.Add(A)
if(EAST)
for(var/atom/A in locate(src.x+item,src.y,src.z))
front.Add(A)
if(SOUTH)
for(var/atom/A in locate(src.x,src.y-item,src.z))
front.Add(A)
if(WEST)
for(var/atom/A in locate(src.x-item,src.y,src.z))
front.Add(A)
return front


And, I have a Stat() to display what is in front(1):


mob
Stat()
statpanel(front(1))


Nothing is displayed in the statpanel, even when an object is right in front of me. How do I fiz my front() proc, or make better use of stat()?
Lord of Water wrote:
I have a proc to return a front list:

mob
var
list
front = ""
proc
front(var/item)
for(var/atom/A in front)
del(A)
switch(src.dir)
if(NORTH)
for(var/atom/A in locate(src.x,src.y+item,src.z))
front.Add(A)
if(EAST)
for(var/atom/A in locate(src.x+item,src.y,src.z))
front.Add(A)
if(SOUTH)
for(var/atom/A in locate(src.x,src.y-item,src.z))
front.Add(A)
if(WEST)
for(var/atom/A in locate(src.x-item,src.y,src.z))
front.Add(A)
return front


And, I have a Stat() to display what is in front(1):


mob
Stat()
statpanel(front(1))


Nothing is displayed in the statpanel, even when an object is right in front of me. How do I fiz my front() proc, or make better use of stat()?



Why do people write such long procs?

Try this:
mob/proc/front()
var/atom/next_loc = get_step(src,dir)
return next_loc.contents


This should return all the objects in the direction you are facing.
In response to Skysaw

Why do people write such long procs?

Usually because they're not experienced enough to know what they're doing, so they're basically just pieceing together bits of what they know to make it work. Procs get shorter as coders get better.
In response to Foomer
Absolutely. I would have never thought of get_step(). Thanks, skysaw!
In response to Lord of Water
[link]

-AbyssDragon
In response to Skysaw
But, what if you only want people in front(1): people one square in front of you, or front(3), up to 3 squares in front of you?

I guess this will be up to me to figure out...
In response to Lord of Water
A loop can accomplish that. Grab the first square in front of you, get_step from that, get_step from that, etc.

-AbyssDragon
In response to Lord of Water
Lord of Water wrote:
But, what if you only want people in front(1): people one square in front of you, or front(3), up to 3 squares in front of you?

I guess this will be up to me to figure out...

If you want something similar to range() and orange() that will also return turfs and such, I suggest this:
proc/front(dist=1,atom/center=usr)  // defaults to usr just like range()
var/_dir=center.dir
var/list/items=list()
while(dist--)
var/atom/a=get_step(center,_dir)
if(!a) return items
center=a
items+=a
items+=a.contents
return items

That code is untested, but I believe it should work.

Lummox JR
In response to AbyssDragon
AbyssDragon wrote:
[link]

-AbyssDragon

Another very nice way of doing it, compliments of the Spuzzster.