ID:170816
 
Hey, I'm working with loops and While() and stuff, and was wondering if using while(world) will create an infinite loop(This is a safety precaution, I am testing it right now, but I'd have to wait a while before I can tell what'll happen.)

Like, right now, i'm using this:

GameController/AI
proc
AI_Manager()
while(world) //While the world is still running
sleep(300) //Sleep for 30 seconds
AI_Walk_Rand() //Call the Walk Rand proc.


Is it ok to use in that situation? I sort of need to find an alternative to an infinite loop, and this seemed like the only way out. (of course, I need it to happen every 30 seconds while the world is still running.
Why not use while(1) ? Its not like the loop is going to continue when you shut the world down.
In response to Foomer
Foomer wrote:
Why not use while(1) ? Its not like the loop is going to continue when you shut the world down.


Ya know..I never thought about that, lol. Well then, I'll just replace while(world) with while(1) then. I'm thinking as long as I leave some sleep() time, it's going to be fine. I've tried it twice: One without sleep(), and one WITH sleep(), the one without experienced extreme lagginess.
In response to Lenox
Yeah a proc that runs as many times as possible every tick usually causes lag. And make sure that you spawn() any new procs from that proc, because if you call a proc straight from within a looping proc, it'll crash the game after about 255 loops.
In response to Foomer
So I should just add this: ?

proc/AI_Manager()
set background = 1
for(var/mob/M in world)
if(istype(M,/mob/Player))
continue //So that we don't accidentally stop the loop, somehow.
else
spawn()
AI_Walk_Rand(M)



Would that basically be what you're saying to add? :P
In response to Lenox
Actually, nevermind, I was thinking of procs that call themselves over and over. :P
In response to Foomer
Foomer wrote:
Actually, nevermind, I was thinking of procs that call themselves over and over. :P

Ok, so I don't have to use spawn() to call a proc?


Thanks for your help, Foomer, I appreciate it :P.