ID:156952
![]() Jun 25 2010, 4:33 am
|
|
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.
|
![]() Jun 25 2010, 6:14 am
|
|
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.
|
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? |
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. |
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() |
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. |
I would recommend using while() or for() to loop the procedure instead of spawn()ing it over... but its your choice *shrugs*
proc |
The peoples republic of china wrote:
Put while(src) at the top of the proc, with sleep(1) right after 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. |