ID:263500
 
Code:
World_Bar_Check()
set category = "GM"
var/global/bccounter =0
for(var/mob/M in world)
if(M.key)
M.BarCheck()
bccounter +=1
usr<< "done.. checked [bccounter] users"
bccounter = 0


Problem description: when this is run (only GMs have this). it is suppose to scan the mobs in the world if it has a key it is suppose to make that mob run the BarCheck proc. However all this does it overload the game (im assuming) and freeze the world. I eventually have to close Dream Daemon to stop the freeze and restart. Whats wrong? i use a similar code for Who and works fine.

What happens in your barcheck proc? Since, like you say, it's a fairly simple loop I'd imagine that barcheck() is the problem.
World_Bar_Check()
set category = "GM"
var/global/bccounter =0
for(var/mob/player/M in world)//the way you were doing it before was searching through all the mobs in the world which is you have alot of mobs is going to cause some lag. Doing it this way may stop most of the lag
if(M.key)//you really don't need this if all players are actual users
M.BarCheck()
bccounter +=1
usr<< "done.. checked [bccounter] users"
bccounter = 0



this should help cut down some lag

In response to Johan411
Checking M.client is probably a better alternative to M.key, as mobs can exist with a key but without a client, where as soon as a client with the key connects they get that mob:
mob/TehBestestGuyInTheUniverse
key = Hazman

//When I connect, the specified mob is created and assigned to me, if one already exists I am connected to it.
In response to Johan411
Better yet, loop through all clients in the world and look at their mobs.

for(var/client/c)
if(!c.mob) continue
c.mob.BarCheck()
bccounter++
As said, your BarCheck() calls must be freezing up the game. Also, why the hell is bbcounter a global var? You're instantly resetting it anyway (assuming BarCheck() doesn't sleep() or something).
In response to Jp
Isn't checking client.mob redundant? If the client exists, it pretty much must have a mob as when a player mob is deleted, the player is logged out.
In response to Kaioken
barcheck does not freeze it, i use it in many parts of the game with no problem.

bccounter is reset after it told the person operating how many it checked (because it use to only check the user this is to prove it checked all the users).
In response to Kaioken
Not necessarily. Players can log in and not have a mob. I don't know how his game is set up, but it's entirely possible that he might be setting client.mob directly, or doing interesting mob-switching stuff that might mess with it.

Basically, it's robust programming.
In response to Jp
I usually do.
for(var/mob/M in world)
if(!M.client)continue
...

In response to Xx Dark Wizard xX
this is what i have now, NOW it does not lag HOWEVER it only checks the user not all the users.

World_Bar_Check()
set category = "GM"
var/global/bccounter =0
for(var/client/c)
if(c.mob)
c.mob.BarCheck()
bccounter +=1
usr<< "done.. checked [bccounter] users"
bccounter = 0
In response to Jp
Ah, so perhaps it is pretty redundant. Obviously no mob-switching will cause a null client.mob, the only way is probably messing with client/New() to delay it's return or whatnot, which isn't really proper anyway.



@Dark Wizard: If you had paid attention to the topic, you would have noticed that it has already been mentioned before. And, also mentioned before, it's slower than looping with for(var/client/C) since in it the code loops threw all mobs needlessly while the other uses the built-in filter and only loops threw actual clients, then uses their mobs.


@Chase_Hammer: Erm, is there actually any other player logged in except you...?
And about the bbcounter, you're missing the point, there's no use in having it a global var and perhaps you don't even know what making it such does. I've seen you needlessly doing this before.
In response to Kaioken
wow....thats a stupid question....

also it WAS going to be used somewhere else but i desided that i did not want to use it i just never changed it...geez its not a big deal