ID:264913
 
Code:
                    for(var/mob/human/x in oview(10))
if(x.name==src.owner)
step_to(src, x,1)
sleep(5)
goto loop


This is suppost to be a proc for an OBJ to follow its owner but this doesn't work

First of all, oview() takes two arguments: a range, and a center. If you only specify the range, then it assumes usr for the center. However, usr is invalid in procs. So, if you are using oveiw() in a proc, always specify two arguments.

Second, never use goto for any reason. while(), for(), and do while() are the proper structures to use for looping.

Third, you do not need to loop through mobs in range. Instead, you should just store a reference to the mob you're following, and follow them. Like so:

obj/follower
var/max_range = 10
var/min_range = 1
var/speed = 5
var/mob/target
New(var/atom/loc, var/mob/target)
..()
src.target = target
// use spawn() so that the procedure creating us isn't forced to wait for us to finish following
spawn() src.follow()

proc
follow()
while(get_dist(src, src.target) <= max_range)
step_to(src, src.target, min_range)
sleep(speed)
// We've exited the loop, which means we are beyond our max range, so delete ourself
del(src)

mob/verb/create_follower()
new /obj/follower(src.loc, src)
In response to Garthor
Yes thank you it is working but after, i tried to change the new location and it doesn't follow anymore

mob/verb
asd()
var/obj/follower/R = new/obj/follower
if(src.dir==NORTH)
R.loc = locate(usr.x+4,usr.y,usr.z)

if(src.dir==SOUTH)
R.loc = locate(usr.x+4,usr.y,usr.z)

if(src.dir==EAST)
R.loc = locate(usr.x+4,usr.y,usr.z)

if(src.dir==WEST)
R.loc = locate(usr.x+4,usr.y,usr.z)

im guessing there is a problem with this
In response to Millennium Earl
You did not create it properly. See my example.
In response to Garthor
I already seen your example but it seems that it is too advanced for me.
Currently im using a proc for a /mob that pulls the obj/follower instead of the obj/follower to follow the mob when it is made.

mob/proc
asdasd()
var/i=4
for(var/obj/follower/T in oview(10))
if(T.owner==src.name)
while(i)
step_to(T,src,1)
sleep(5)
i--
del(T)

Right now, whenever i make the follower 4 tiles away, it automatically executes this proc which works fine but i want to understand yours properly. Could you explain a little more? I dont quite understand how yours work
In response to Millennium Earl
Ok, i tried to make a proc for the /obj/follower again

obj/follower
proc
followowner()
var/i=4
while(i)
step_to(src,src.owner,1)
sleep(2)
i--
del(src)
theicon
icon='dfsfiojd.dmi'
New()
..()
spawn() src.followowner()
mob/verb
makefollower()
var/obj/follower/theicon/T = new/obj/follower/theicon
T.loc=locate(usr.x,usr.y+4,usr.z)
T.owner=usr.name

but it still doesn't follow
Can you please or someone else help me?
In response to Millennium Earl
Ok nevermind! After so many experiments, i finally got it!!
In response to Millennium Earl
If you check your similar post on the Developer How-To forum, I posted a solution for you.