ID:158256
 
I've noticed that get_step() doesn't work when you're trying to do it with turfs...ie for(var/turf/T in get_step(src, dir))

Is there any alternate way of getting something to return the turf in front of you? I'm trying to make an action button

    verb
Action()
//if(doing_action) return
world << 1
for(var/NPC/N in get_step(src, dir))
world << N
if(N)
doing_action = 1
N.Talk()
doing_action = 0
break

for(var/turf/powerline/bottom/L in step(src, dir))
doing_action = 1
L.Climb()
doing_action = 0
break

for(var/turf/powerline/bottom_right/R in get_step(src, dir))
world << R
doing_action = 1
R.Climb()
doing_action = 0
break

for(var/turf/T in get_step(src, dir))
world << T
if(T && T.jumpable)
locked ++
frozen ++
icon_state = "jump"
pixel_y = 32
loc = locate(T.x, T.y, T.z)
sleep(3)
locked = max(0, locked - 1)
frozen = max(0, frozen - 1)
pixel_y = 0
icon_state = null


I've never really done an action verb like this, but is there a better way to do it? :|

[edit]
Now that I think of it..could something like this work?

atom
verb
Action()

NPC
Action()

mob
Action()
for(var/atom/A in get_step(src, dir))
A.Action()

The reason is that get_step() returns the turf itself. Obviously, the turf can't be in itself.
var/turf/T = get_step(src,dir)
var/turf/T = get_step(usr,usr.dir)
return T


You were searching for a turf in a turf's contents.
In response to Andre-g1
Andre-g1 wrote:
> var/turf/T = get_step(usr,usr.dir)
> return T
>

You were searching for a turf in a turf's contents.

Now see i've tried that before and it still didn't seem to work.
In response to Axerob
get_step() itself returns the turf. What you do in something like "for(var/mob/m in get_step(src, dir))" is the same as "for(var/mob/m in [turf returned by get_step(), being the contents of it])".
In response to Kaiochao
Ah I see, thanks for clearing it up. But look at the edit I made a few minutes ago, would it be possible to do something like that?
Axerob wrote:
I've noticed that get_step() doesn't work when you're trying to do it with turfs...ie for(var/turf/T in get_step(src, dir))

Of course, as has been said, get_step(src, dir) is the turf in front of you (or null if you're facing the edge of the map).

Is there any alternate way of getting something to return the turf in front of you? I'm trying to make an action button

>           for(var/NPC/N in get_step(src, dir))


This of course loops through all /NPC objects located in front of you. I assume that's what you wanted.

[edit]
Now that I think of it..could something like this work?

> atom
> verb
> Action()
>
> NPC
> Action()
>
> mob
> Action()
> for(var/atom/A in get_step(src, dir))
> A.Action()
>


Except I'd make it a proc instead and pass the caller as an argument:

atom/proc/action(my_arg)   // my_arg keeps track of who called action()

mob/verb/blah()
for(var/atom/a in get_step(src, dir))
a.action(src)


You might also consider making action() return a value to indicate if something happened and cause blah() there to stop after the first action. This way you might, say, have 10 balls in a location and pick them up one at a time.

atom/proc/action(my_arg)
return 0

npc/action(my_arg)
my_arg << "You performed an action on [name]!"
return 1

mob/verb/blah()
for(var/atom/a in get_step(src, dir))
if(a.action(src))
break // stop doing actions