ID:2268339
 
(See the best response by Kaiochao.)
Code:
/obj/screen/hand/l_hand
name="Left Hand"
icon='icon/interface.dmi'
icon_state="l_hand_inactive"
New(client/c)
screen_loc="3,1"
c.screen+=src
Click()
if(activehand=="Left")
return
if(activehand=="Right")
handchecker_icon()
/obj/screen/hand/r_hand
name="Right Hand"
icon='icon/interface.dmi'
icon_state="r_hand_inactive"
New(client/c)
screen_loc="2,1"
c.screen+=src
Click()
if(activehand=="Right")
return
if(activehand=="Left")
usr<<"test"
handchecker_icon()
return
/obj/screen/hand/proc/handchecker_icon()
var/obj/screen/hand/r = /obj/screen/hand/r_hand/
var/obj/screen/hand/l = /obj/screen/hand/l_hand/
if(activehand="Right")
r.icon_state="r_hand_active"
l.icon_state="l_hand_inactive"
return
if(activehand="Left")
r.icon_state="r_hand_inactive"
l.icon_state="l_hand_active"
return


the error
runtime error: Cannot modify /obj/screen/hand/r_hand.icon_state.
proc name: handchecker icon (/obj/screen/hand/proc/handchecker_icon)
usr: Salazar Neck Twister (/mob/human)
src: Left Hand (/obj/screen/hand/l_hand)
usr.loc: Magi Turf (6,10,1) (/turf/floors/Magi_Turf)
src.loc: null
call stack:
Left Hand (/obj/screen/hand/l_hand): handchecker icon()
Left Hand (/obj/screen/hand/l_hand): Click(null, "mapwindow.map", "icon-x=16;icon-y=19;left=1;scr...")

Problem description: So it is supose to change the selected hand, and it is supose to indicate that by changing icon_states from inactive to active. But when i try to switch hands, i get this error. Any ideas on what im doing wrong
If it is failing to change the icon state, that is probably because the thing you are trying to change doesn't exist. Are you sure you have a valid reference to the object you are modifying an icon_state for?
In response to Foogimicester
So i think that is it, but how do i refer to it after the obj is created?
This is how it is created at the start.
    Login()
new/obj/screen/hand/l_hand(src.client)
new/obj/screen/hand/r_hand(src.client)
In response to Killerken924
Best response
When you do "new/type(...)", that doesn't just create an object, it also acts as a "reference" to the object that was created. So, you can stick it in a variable, like so:
mob/whatever
// You can declare multiple variables like this to avoid repetition:
var obj/screen/hand // this is part of the type of the variables
l_hand/left_hand // this has the type /obj/screen/hand/l_hand and is named "left_hand"
r_hand/right_hand // and similar here for the /.../r_hand

Login()
// Instantiate the variables
// You can leave out the type after "new" so it'll automatically
// use the type that the variable is declared with
left_hand = new(client)
right_hand = new(client)

// Now, in your hanchecker_icon(), you can use usr.left_hand and usr.right_hand
// to refer to these objects again.

The problem with your current code is that type paths aren't the same as the instantiated objects. You can have many objects of the same type, but the type itself isn't actually an object.