ID:139121
 
Code:
var
Players = list() // Players in queue
Game // Game going on or not


Problem description:
Well, the game I'm trying to make has a global Player list (those in the game) and the game var is to check whether they're playing or not. My problem is that this is not working. Either this is not the way to go about a world list or

        Start() // Start the game 
if(length(Players) >= 1) // At least 2 to start a game
world << "A new battle has begun!"
while(Players) // While the Players list still has values
var/mob/A = pick(Players) // Pick a mob at random
for(var/mob/M in world)
if(M.name == A)
Players -= A // Remove them from the list (So that they're not moved again and so that the game knows when to stop)
M.loc = locate(13,13,2)
M.loc = pick(/area/Spawn) // Spawn them at a Spawn point
M.icon = 'Boats.dmi'
else // If there are not enough people to start a game
src << "There must be at least 2 People to start!"

Join() // Join the game
Players += "[src.name]" // Add player to Player list
// Add a removal of Join verb to prevent abuse

Leave() // Leave the game
Players -= "[src.name]" // Remove player from Player list
is wrong. Which is it?
Emptying a list doesn't delete the /list instance itself, so your while() condition will always be true.

If there's not an infinite loop currently, it's probably because it's crashing on a pick() from an empty list.
In response to DarkCampainger
Hmmm, I guess I should change that to length
In response to Lugia319
I was actually testing your snippet when dark replied, it's crashing for the exact reason he stated.


Do another len check in the while and your good to go; also, checking for len >= 1 means it only needs one person in the list, check for 2 or more.
In response to Lugia319
Three more things:

You're adding the mob's name to the list, but then removing the mob itself under start. (nevermind, you typecast 'A' as /mob, but it's actually text)

Setting a mob's loc to a /area will place it at the bottom-left-most (usually) turf in that area. You may want to pick() the area, and then pick a turf from its contents.

You should probably be storing the actual mobs in the Players list. Then if someone logs out and you delete their mob, they'll be automatically removed. Also, you could then do for(var/mob/m in Players) instead of trying to match up the names.
In response to Jotdaniel
The while() should only check to see if there are people left to move. The first one is so I can test it solo. I intend to fix it later
In response to DarkCampainger
Thanks for all the help. I forgot about the turf thing, I was trying to remember code from Shootemups (which is lost on a dead computer :'( when I wrote it) I'll fix the code promptly. Thank you for your help.