ID:160399
 
Well, when coding my game if I need to define a group of mobs in a list, I use the for( ) Proc.
Is there some other way I can define a group of mobs into a list variable without using for( )

my uses have been as such...

mob
verb
Who()
src<<"Players online:"
for(var/mob/m in world)
src<<"[m.name]"


Is there any way I can get this same effect without ever using for( )? Or am I doomed to have a bunch of infinite loops running around in my game?

(Note: I've also tried var/mob/m = locate(/mob/ in world) but that only brings up one mob each time, I need all the ones online. [I use if(m.client) to keep the NPC's out of that])
You can use a list that adds a player when they login and removes when they logout, Kaoru.

Then you would only loop through a list instead of looping through the world.contents.
Or list through the clients
In response to Andre-g1
Creating a list is eaiser upon client/new and del
Bravo1 wrote:
Is there any way I can get this same effect without ever using for( )? Or am I doomed to have a bunch of infinite loops running around in my game?

I'm not really sure of your point here. That's not an infinite loop; it's called only when the verb is called, and runs just once, looping through every mob in the world, then ends. That's a perfectly standard and fine way to find the mobs.

An infinite loop would look like this:
proc/test()
for()
world << "blah"
// this point is never reached

Using for() like that (with the empty brackets) is an infinite loop that never exits (unless you manually break out of the loop), similar to while(1) or the like. That is generally a bad design, especially if the loop never sleeps.

In response to Hobnob
Break statement for the win. Plus, what if you do need an infinite loop :P (it would have to sleep, of course!).