ID:272794
 
How do you make a loop into an AI system?
That's way too generic of a question to be answered...
You could be asking about any number of things.

First could be a for() loop for finding mobs, that would be done by looking up for() in the DM Reference.
for(var/mob/M in oview(5))
M.HP+=1

This will loop through every mob in a 5 tile radius and give him +1 HP (not counting the user himself)

Another would be a repeating AI system to repeatedly check for something. That would be done as simply as creating a looping proc with a sleep() in it then calling it at new().
mob/Monster/New()
..()
spawn()AIProc()

mob/Monster/proc/AIProc()
while(src)
for(var/mob/M in oview(3))
step_to(src,M)
break
sleep(10)

That would cause the monster to step towards any mobs in a 3 tile radius every 10 ticks (1 second).

If you want a more specific answer you need to ask a more specific question.
In response to AJX
There is usr abuse in those examples. As you of course supply no center atom to use with a call like oview(3), it obviously has to use something for it, and what it uses is the default value of its Center arg, usr. Common mistake.
Other less important small things about the code:
  • Using ++ is a little better than += 1.
  • Instead of using a for() loop and breaking no the first iteration, you should just grab the first object found with a call to locate() then use it if one was found.
  • Unlike with other objects, checking if src still exists is pretty extraneous; such a check will normally never execute when it's going to fail, as the proc would have stopped before that. So you can use for() instead to loop with no condition.
In response to AJX
I beleive what he wants is to make an infinite loop in a proc to make monster AI. Make the monster walk to the mob, attack, etc.