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)
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.
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
#5 Mar 29 2011, 7:50 pm (Edited on Mar 29 2011, 7:56 pm)
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: