ID:2271452
 
(See the best response by Mad Snail Disease.)
So this is the original code

world/proc
StartAutoEvent()
set waitfor = 0
var/eventlist=list("PvP","Race","Free for All")
var/event=pick(eventlist-LastEvent)
LastEvent=event

world<<output("<font size = 3><center><font color=green>The Event [event] will start!","output2")
world<<output("<font size = 2><center>(The Register for the Event is Open! 3 Minutes Duration!)","output2")

InWaiting=list()
RegisterOpen=1

sleep(1800)
RegisterOpen=0

if(InWaiting.len<4)
for(var/mob/Z in InWaiting)
Z:inregister=0
InWaiting=list()
world<<output("<font size = 2><center><font color=red>Event [event] was canceled because few people registered","output2")
return

switch(event)
if("Race")
InitiateRace()
if("PvP")
InitiatePVP()
if("Free for All")
InitiateFFA()


And then I changed it to this to open an window for players to press a button to register to the event...

world/proc
StartAutoEvent()
set waitfor = 0
var/eventlist=list("PvP","Race","Free for All")
var/event=pick(eventlist-LastEvent)
LastEvent=event

world<<output("<font size = 3><center><font color=green>The Event [event] will start!","output2")
world<<output("<font size = 2><center>(The Register for the Event is Open! 3 Minutes Duration!)","output2")

InWaiting=list()
RegisterOpen=1

for(var/mob/player/M in players-staffers)
var/mapfocus=0
if(winget(M,"win_main.map","focus=")=="true")//If their map was focused
mapfocus=1

winset(M,"win_register.name","text=\"The Event [event] will start!\"")
winshow(M,"win_register", 1)
if(mapfocus)//Focus it again, so it doesn't disturb pvp's, etc...
winset(M,"win_main.map","focus=true")

sleep(1800)
RegisterOpen=0//The code breaks before this happens

for(var/mob/player/M in players-staffers)
winshow(M,"win_register", 0)

if(InWaiting.len<4)
for(var/mob/Z in InWaiting)
Z:inregiser=0
InWaiting=list()
world<<output("<font size = 2><center><font color=red>Event [event] was canceled because few people registered","output2")
return

switch(event)
if("Race")
InitiateRace()
if("PvP")
InitiatePVP()
if("Free for All")
InitiateFFA()


But it so happens that after I've done this, the code breaks before closing the register (with 'RegisterOpen=0', as marked on the code above). I was guessing something like players disconnecting before the code within for was done but it doesn't give out runtimes either, so what can I possible be doing wrong? Thanks in advance.
How does the code "break"
In response to Dragonpearl123
As in it stops where I mentioned, not running the rest of the code after it.
Throw some debugging code in there to see whats going on:
        for(var/mob/player/M in players-staffers)
world.log << "Looping for [M]"
var/mapfocus=0
world.log << "mapfocus set to 0"
if(winget(M,"win_main.map","focus=")=="true")//If their map was focused
world.log << "Their map was focused."
mapfocus=1
world.log << "mapfocus set to 1"
else
world.log << "Their map was not focused."
winset(M,"win_register.name","text=\"The Event [event] will start!\"")
world.log << "Got here..."
winshow(M,"win_register", 1)
world.log << "And here."
if(mapfocus)//Focus it again, so it doesn't disturb pvp's, etc...
world.log << "mapfocus was set"
winset(M,"win_main.map","focus=true")
world.log << "Setting focus=true"
else
world.log << "mapfocus was not set."
world.log << "Loop finished for [M]."
world.log << "All loops finished. Sleeping for three minutes..."
sleep(1800)
world.log << "Done sleeping"
RegisterOpen=0//The code breaks before this happens
world.log << "Set RegisterOpen=0"


etc...

Might let you figure out exactly where it's dying.
In response to Flick
Added the debug code, tomorrow I'll reboot the live game, see the results and post them here.
In response to Flick
Ok tested it out and found that the proc stops after "mapfocus set to 0". This still leaves me clueless.
you threw a for() loop in there with what is assumingly supposed to be a player clientlist and threw a winget() in there

if you have ANY NPCs in the "players-staffers" list, winget() will crash the proc entirely. If this is the case, do a

If(!M.client) continue

at the start of that for() loop and try again

It could also be that your list "players-staffers" has no players in it? I don't know how you structure your lists. But if it's crashing at the winget() there's a problem with that winget.
I don't use winget a lot, and haven't at all in quite a while, but is that supposed to be "focus=" or just "focus"?

You could throw another debug in there to check for M.client as well. That sounds like a likely issue.
correct, "focus=" is not correct syntax for winget()

but he claims that "focus=" worked before he added the code so i'm assuming that's not what caused his issue

correct syntax is just "focus"
In response to Flick
Mista-mage123 wrote:
you threw a for() loop in there with what is assumingly supposed to be a player clientlist and threw a winget() in there

if you have ANY NPCs in the "players-staffers" list, winget() will crash the proc entirely. If this is the case, do a

If(!M.client) continue

at the start of that for() loop and try again

It could also be that your list "players-staffers" has no players in it? I don't know how you structure your lists. But if it's crashing at the winget() there's a problem with that winget.

There are no npcs in the players-staffers list. Mobs are removed from these lists when they Logout.

What could possible be happening I think is M turnin null before the winget. But I'm not getting runtimes in the log. Should I add an if(M) check?

If the list had no players then nothing on the for would run I think.

Flick wrote:
I don't use winget a lot, and haven't at all in quite a while, but is that supposed to be "focus=" or just "focus"?

You could throw another debug in there to check for M.client as well. That sounds like a likely issue.

The correct syntax is "focus", people tipped me about it but I debugged the code after I had already fixed this and it continues to happen. "focus=" may not be the correct form but it works in other instances that I used it so I think it's irrelevant.
Best response
Well from the debug code, the issue is definitely with that first winget() call. I rarely use these procs , but the documentation says that "because the client must be contacted to get this information, winget() will sleep the current proc."
That makes it sound very likely that Flick is correct, and a disconnected player might hold everything up. Try adding an extra check for that before the winget() call, like so:
        for(var/mob/player/M in players-staffers)
world.log << "Looping for [M]"
var/mapfocus=0
world.log << "mapfocus set to 0"
if(!M.client) world.log << "player had no client"
if(winget(M,"win_main.map","focus=")=="true")//If their map was focused
world.log << "Their map was focused."
mapfocus=1
world.log << "mapfocus set to 1"
else
world.log << "Their map was not focused."
Mista-mage suggested the missing client first, but yeah, that sounds like it.
usually when I use winget in my games, I put

if(!M||!M.client) continue

to avoid these types of problems. maybe not the most optimal way to go around it but it gets the job done.

[quote]What could possible be happening I think is M turnin null before the winget[/quote]

It's really starting to sound like what's happening is that there are mobs not being properly removed from your staffers list upon log out, or there are mobs in there that shouldn't be in there. Regardless, doing a !M check prior to the winget should fix that issue. You should include at the start of a loop, before the winget "Checking [M.name]" to confirm this is the case.
In response to Mista-mage123
Yeah I threw in those checks at the beginning, will return the results when I test it out.

The mob is added in the staffers list at the same time it is on the players list (if it is a staffer) and on the Logout() proc, the mob is removed from both lists. The problem doesn't lie here I think.
Some other things I noted about that winget() call

"win_main.map","focus=")=="true"

Are you sure the name of the control is just "map"? Generally, when you add a map control to your skin, BYOND makes the first map's name "map1", so you would have had to manually change "map1" to "map" in order to use that winget() call the way you wrote it

winget() will crash in under 3 circumstances:
1. The client is invalid
2. The target control or target window is invalid
3. The variable is invalid

You claim "focus=" works, so that might not be the issue, I would still advice changing it to "focus". But check to make sure the name of the control is indeed "map" instead of "map1".
In response to Mista-mage123
I'm sure the name of the control is just "map", without an 1, double checked it right now just for the sake of it.

I claimed "focus=" worked but still changed it to "focus" before I debugged the code as I said it in this thread, just to minimize potential errors.

The proc still crashes tho. It's not an invalid target or variable since it works many times, stopping the proc only sometimes, leaving me to believe it is a client error.

I added the
if(!M||!M.client)continue
bit before the winget but the error still continues at the same place (before/at the winget).