ID:171204
 
mob
proc
walkforever()
while(!inview)
var/list/dirs = list(NORTH,NORTHEAST,NORTHWEST,SOUTHEAST,SOUTHWEST,SOUTH,EAST,WEST)
var/a = pick(dirs)
Walk(rand(1,10),a,8)
spawn(30) walkforever()
Walk(Steps as num, Direction, Speed as num)
while(Steps)
Steps--
step(src,Direction)
sleep(Speed)


This is my only code for the npc, when the npc is made, it spawns this proc.
But, eventually the npc starts moving really fast, and starts lagging up the game, till eventually its practically frozen up.
Why is it doing that?

Thanks,
Farkas
Couldn't you just use walk_rand()?
Farkas wrote:
>       walkforever()
> while(!inview)
> var/list/dirs = list(NORTH,NORTHEAST,NORTHWEST,SOUTHEAST,SOUTHWEST,SOUTH,EAST,WEST)
> var/a = pick(dirs)
> Walk(rand(1,10),a,8)
> spawn(30) walkforever()


But, eventually the npc starts moving really fast, and starts lagging up the game, till eventually its practically frozen up.
Why is it doing that?

Lets go through this bit by bit.

'while(!inview)' while the inview var is false, perform the following.
'spawn(30) walkforever()' spawn off another walk forever proc in 3 seconds/30 ticks.

This are the only things needed to find out why this is happening. Basically, while the inview variable is false, it will keep spawning off new versions of the walkforever proc. At first, there is just the first one. Then there would be 2, then 4, then 8, and so forth, until the inview var becomes true. Perhaps you have the spawn(30) walkforever() line tabbed once too much?
In response to Lazyboy
thanks very much, that solved my problem

Farkas
In response to Farkas
another problem, When a player clicks on the mob, the mob follows, but when u speak to another NPC, i want it so the mob goes off and walks around again as normal, thats why i have while(!inview). but this isnt happening

                            for(var/mob/M in world)
if(M.inview)
M.inview = 0
walk(M,0)
M.walkforever()


I found in the reference walk(M,0) cancels out walk_to. however, the mob is walking away but wants to walk to the player aswell o_O so the mob is doing a beautiful dance around the player as it is both trying to walk around randomly and also, walk towards the player.

the code for walking to the player is walk_to(src,usr,1,5)

Whats wrong now >_<

Thanks in advance

Farkas