ID:145404
 
mob
proc
thing()
var/obj/hud/A
if(usr.blah == 1)
A = /obj/hud/thing
if(usr.blah == 2)
A = /obj/hud/thing2
for(A in src.client.screen)
A.icon_state == "thing"


K well theres my code.. But it doesnt work, it changes every hud icon instead of what i want it to change. I would like it to if blah equals 2 then the hud that changes is obj/hud/thing2. Is there a way to do this? (And it needs to go through this If statement)

X0Gohan0X

put a proc to check it

EDIT: O_O its a proc?sorry, i "saw" a obj o_o
No put usr in proc. Ungh.

Lummox JR
In response to Lummox JR
err I had src.. but I was testing some different ways to see if it would work.. I usually dont use usr unless its after Click().

Anyone can someone actually provide some help instead of critisicm?
In response to X0Gohan0X
X0Gohan0X wrote:
err I had src.. but I was testing some different ways to see if it would work..

Changing from right code to wrong code to see if it still works is indefensible. Don't do it.

I usually dont use usr unless its after Click().

In Click() is fine, but in procs called by it, absolutely not.

Lummox JR
In response to Lummox JR
It is called by click so there is no possible way for it to do anything wrong but yeah I understand that its bad coding..

And whats wrong with usr if you need to refrence the thing that called your proc? It would save you a step.
Looping does not work that way. When you loop through a list, it will go through everything in the list that is the type of or a type derived from the variable's type. Since A is for type obj/hud/A it will loop through all objects of type /obj/hud in the list.

Make a second variable, set that to a type path, then check to see if A.type==type_path inside the loop.
In response to X0Gohan0X
X0Gohan0X wrote:
It is called by click so there is no possible way for it to do anything wrong but yeah I understand that its bad coding..

Yes, there are plenty of ways it could go wrong: Something else could call it.

And whats wrong with usr if you need to refrence the thing that called your proc? It would save you a step.

Because the thing that called your proc is either a verb or another proc. Players don't initiate procs; they initiate verbs. Once you get past the verb level, usr is meaningless and dangerous.

Lummox JR