ID:156952
 
I was wondering, since I need to msake it so that the npcs Hsve actually AI, how would I make it that there is an infinite loop? I've tried to use spawn while(), but I keep getting an error saying empty type name or something like tht, if anyone can help it would be much apprecited.
It's quite simple. I've made a small example for you that should give you a good idea of how to go about doing this.

mob
npc
name = "Guy"
proc
ai()
..() // replace this with the ai actions

spawn(10) // wait one second, up to you
src.ai() // call it again
world/New()
..()
for(var/mob/npc/n in world) n.ai()
In response to Cloud 10
Thanks, that should help a lot. Much appreciated.
In response to Cloud 10
I appreciate the help, but I need more;

[code]
world
mob = /mob/survivor
New()
..()
for(var/mob/zombie in world) src.roam()


[/code]

The problem is I can't get it to recognize the proc and run it, how do I fix it?
In response to CodeWeasel22
Well, it should be:

for(var/mob/zombie/z in world) z.roam()


Try doing that, and if it still doesn't work, show me the proc.
In response to Cloud 10
Wait wait, what is this whole variable z thing?
In response to CodeWeasel22
CodeWeasel22 wrote:
Wait wait, what is this whole variable z thing?

You put var/mob/zombie. You never set the zombies variable, you just told the system that you're using the zombie mob. You need to make it var/mob/zombie/z to give the zombie a variable so you can call the proc.

for(var/mob/zombie/z in world) z.roam()
In response to CodeWeasel22
Look up 'var' and see how variables are declared.
var/A


This declares a variable named A. Its type is undefined.

var/mob/M


This declares a variable named M. Its type is defined as /mob.

var/mob/player/Player


This declares a variable named Player. Its type is defined as /mob/player.

var/mob/zombie


This declares a var named zombie. Like with M before, its type is defined as /mob.

var/mob/zombie/zombie


This declares a var named zombie. Its type is defined as /mob/zombie.
In response to Cloud 10
I would recommend using while() or for() to loop the procedure instead of spawn()ing it over... but its your choice *shrugs*
    proc
ai()
..() // replace this with the ai actions

for() // or while(src), etc. These are infinite loops
Doing stuff // call it again
sleep(delay time) // time to delay before looping back

In response to GhostAnime
Put while(src) at the top of the proc, with sleep(1) right after it.

That -should- do it.
The peoples republic of china wrote:
Put while(src) at the top of the proc, with sleep(1) right after it.

That -should- do it.

What should that do?

while(src) is equivalent to while(1) or for(). If you delete an object all procs belonging to it stop, so the proc will stop because of this before it would stop because src becomes null. You're not wrong but it's worth knowing that it isn't needed. You can use to easily terminate loops by deleting the object containing the loop (for example, you can put a global loop inside of an object so you can easily stop the loop).

Having a delay at the start of the loop may or may not be a good thing, depends on the situation. It is often overlooked, but in this case I wouldn't expect it to cause any problems.