ID:142323
 
Code:
mob
Login()
switch(input("What team would you like to join?(Requires GM approval)",text) in list ("blue","red"))
if("blue")
for(var/mob/M in world)
if(M.GM == 1)
switch(input(M,"[src] wants to join blue team. agree?",text) in list ("yes","no"))
if("yes")
src.team = "blue"
src.overlays += 'blueover.dmi'
switch(input("What task force do you want?",text) in list ("delta force","SAS","korean special force"))
if("delta force")
src.icon = 'Delta force.dmi'
if("SAS")
src.icon = 'SAS.dmi'
if("korean special force")
src.icon = 'KSF.dmi'
switch(input("ready?",text) in list ("yes","no"))
if("yes")
if(src.team == "blue")
src.loc = locate(1,1,1)
usr.overlays += 'blueover.dmi'
else
src.loc = locate(1,70,1)
src.overlays += 'redover.dmi'

if("no")
src<<"[M] declined! try joining the other team!"
return
if("red")
for(var/mob/M in world)
if(M.GM == 1)
switch(input(M,"[src] wants to join red team. agree?",text) in list ("yes","no"))
if("yes")
src.team = "red"
src.overlays += 'redover.dmi'
switch(input("What task force do you want?",text) in list ("delta force","SAS","korean special force"))
if("delta force")
src.icon = 'Delta force.dmi'
if("SAS")
src.icon = 'SAS.dmi'
if("korean special force")
src.icon = 'KSF.dmi'
switch(input("ready?",text) in list ("yes","no"))
if("yes")
if(src.team == "blue")
src.loc = locate(1,1,1)
src.overlays += 'blueover.dmi'
else
src.loc = locate(1,70,1)
src.overlays += 'redover.dmi'
if("no")
src<<"[M] declined! try joining the other team!"
return


Problem description:
i know there is a problem with this code... but i cant find it. in game, when i choose a team i get runtime error.
runtime error: bad client
proc name: Login (/mob/Login)
source file: main.dm,7
usr: Gogeta126 (/mob)
src: Gogeta126 (/mob)
call stack:
Gogeta126 (/mob): Login()
and nothing happens afterwards
First off, this login system is fatally flawed by the fact that you have to ask permission of a GM before you can join a team. If you're going to implement team joining in a way that requires permission, you need to do that well after Login(). You also need a fallback in case no GMs are present.

Second, this proc is chock full of usr abuse. You should be using src in Login(), not usr because it isn't safe.

As for the particular error you have, "bad client" comes up when you're trying to use input(), alert(), etc. on a mob that has no client. So in this case, a GM mob has been found, only the GM happens not to be online. The code is trying to ask a dead husk for permission and when it realizes no one is really there to ask, it throws the error.

Lummox JR
In response to Lummox JR
usr abuse... oh yes i see... 1 mistake. This will be an action game(shooter..) and it will be run by a gm so that GM has to be online otherwise its no game... and well, ive set the var GM to 1 temporarily just for me to test, later on i will specify which keys get the gm var.

As for the particular error you have, "bad client" comes up when you're trying to use input(), alert(), etc. on a mob that has no client. So in this case, a GM mob has been found, only the GM happens not to be online. The code is trying to ask a dead husk for permission and when it realizes no one is really there to ask, it throws the error.

can you explain in a bit more detail please?
In response to Gogeta126
You need to change if(M.GM) into if(M.GM&&M.client).
Checking if a person is connected to the mob as well as being a gm...
In response to Naokohiro
Correct. Such vars (as well as GM verbs, while on a related subject) should really just be placed on the /client object itself and not on the mob, which avoids this and other problems.