ID:174546
 
1) Okay, here I am trying to create a loop with music, can you help me?

2) My monsters won't randomly move...what do I do?
mob/NPC
Sheep
icon='animals.dmi'
icon_state="sheep"
density=1
var/mob/P
proc/Wander()
while(src)
var/Found = 0
for(P in oview(5))
step_towards(src,P)
Found = 1
break
if(Found != 1)
step_rand(src)
sleep(10)
sleep(5)
spawn(5)
Wander()

Click()
usr<<'Sheep.wav'

The only problem is he isn't moving.
1) Look up sound() in the reference.

2) Not sure about this, but change this:

for(P in oview(5))

To this:

for(P in oview(5,src))

The current version is using "usr" as the default argument, which is not good. You definitely need src in this case.
In response to Crispy
About the not moving part, you only defined the procedure, you didnt start it, add
New()
Wander()
another thing is, since theres a while proc in there, why wait five ticks and call it again? Wouldnt that cause an infinite loop?
In response to Wanabe
I didn't look at this code that much, but I'm guessing so the NPC would walk... again? Not just stop after one step.
In response to Wanabe
Good catch, FranquiBoy - I can't believe I missed that. =) My advice still stands, though, as the bit I mentioned could still cause problems.

Wanabe wrote:
another thing is, since theres a while proc in there, why wait five ticks and call it again? Wouldnt that cause an infinite loop?

You're right. The "while(src)" line should be deleted and everything that used to be in that loop should be unindented once. It won't change much, except that spawn() is faster than the combination of while() and sleep().