ID:163423
 
Well I made a small little code for npcs to rand walk and eat food if its in its view, but.. I have a feeling the food is freezing my server up, cus it somehow turns into a inf loop. well heres what I got... Any fixes plz? :).

obj/npcs/animals
var/eatsfodder=0
var/fed=0
var/age=0
var/speed=0
var/waitforowner=0
var/likeness=0
proc
randwalk()
START
var/a=0
var/didit=0
sleep src.speed
if(eatsfodder)
if(!src.fed)
for(var/obj/items/fodder/F in oview(src,5))
if(F.owner==src.owner)
if(!didit)
a=1
didit=1
src.dir=get_dir(src,F)
step(src,src.dir)
if(locate(F) in src.loc)
del F
src.fed=1
if(src.likeness<=199)
src.likeness+=1

for(var/mob/M in world)
if(src.loc==M)
a=1
if(src.waitforowner)
if(src.owner=="[M.name]")
if(M in oview(src,2))
a=1
if(a==0)
step_rand(src)
goto START



Much Appreciated =).
Bump()

No help? :(.
        randwalk()
START
// ...
goto START


There's your infinite loop. Using goto in that capacity isn't a good idea anyway, use a while or do while loop instead.
That alone shouldn't be freezing it up, since you're calling sleep inside there, but it's still a good idea to fix it.

Secondly, I'm not really sure what your objective for the food part was, but currently it makes the animal move one tile towards every piece of food within 5 tiles, then eat it only if it ends up in the same tile as the food (in other words, if the food was 1 tile away).