ID:142105
 
Code:
mob
Login()
..()
spawn for()
sleep(10)
for(var/obj/Element_Switcher/Element_Display/E in usr.client.screen)
E.M_Type=usr.Element//dis line
mob
var/Element_Next="Fire"
verb/Add_Fire()
Elements+="Fire"
obj/Element_Switcher
icon='Element Switcher.dmi'
screen_loc="14,17"
layer=50
Element_Display
icon_state="Un_Armed"
var/M_Type="Un_Armed"
New()
spawn for()
src.icon_state="[M_Type]"
sleep(10)
Right
icon_state="right"
var/Element_Next="Fire"
screen_loc="15,17"
Click()
usr.Element_Switch_Right()
Left
icon_state="left"
screen_loc="13,17"
Click()
usr.Element_Switch_Left()

runtime error: Cannot read null.screen
proc name: Login (/mob/Login)
source file: ElementSwitcher.dm,7
usr: \[Owner] Nategrant (/mob)
src: \[Owner] Nategrant (/mob)
call stack:
\[Owner] Nategrant (/mob): Login()

Problem description:
Whenever someone logs out I get the following runtime error, any help? Thanks
Your infinite loop under Login() doesn't check to see if your usr still exists. After someone logs out, usr doesn't exist and it still tries to find objs in usr.screen, which doesn't exist, therefore giving you a runtime error. Just run a check in your for() loop to see if us still exists.
In response to Hiro the Dragon King
mob
Login()
..()
spawn for()
sleep(10)
if(usr)
for(var/obj/Element_Switcher/Element_Display/E in usr.client.screen)
E.M_Type=usr.Element

If this is what you ment it didn't work
In response to Nategrant
1.does it do it even when you join your own game?

2.it should be after for() but before the other piece of code, because once it starts the loop, it only reads the code after for() and u put it before the for() loop.
1) usr abuse.
2) When a client is deleted, it calls mob/Logout(). If your mob/Logout() doesn't delete the mob within 1 second (or whatever is left of the sleep) of the client being deleted, the client var is null. This is what caused your error, most likely.
In response to Nategrant
No, what he meant was:

1) usr abuse
2) just because the mob exists, doesn't mean it has a client. you need to verify that the client exists before attempt to read or modify the client's data. so:

mob
Login()
..()
spawn()
for() // or you can do while(1)
if (src.client)
// whatever
In response to Keeth
Quick "Trick":
> mob
> Login()
> ..()
> spawn()
> while(src.client)
> // whatever
> sleep(whatever)
>
In response to Kaioken
or...
mob
Login()
..()
spawn for()
sleep(10)
if(client)
for(var/obj/Element_Switcher/Element_Display/E in usr.client.screen)
E.M_Type=usr.Element
In response to Nategrant
This is quite the same version I was fixing... o_O
Why have your code worse since it's needlessly longer - you're using no condition in the looping construct (incidentally for() can be used like that as well) but then again you're checking for a condition each iteration manually - why contradict yourself? ;) Just have the condition in the loop construct as more normal.

Also, that version causes the loop not to break when there is no longer a player, which is bad. Indeed, the loop will be restarted anyway when/if he returns, and duplicates of it could run this way.

Lastly, you should really stick to using src only in Login(), but if you're gonna use usr then don't mix them. Your code there uses both src and usr; always stick to one in situations either can be used (src is often the most robust to use at those times).