ID:172582
 
I'm working on a HUD for my zelda game, and so far it's up. but I'm trying to make it change bweapon's icon_state to "rusty", but i keep getting an undefined var error. What the problem?

Here the code where I define bweapon:
obj
hud
layer = MOB_LAYER + 1//appears above mobs
icon = 'hud.dmi'

declarations for other parts of my hud

bweapon
layer = MOB_LAYER + 2
dir = NORTH
icon = 'weapons.dmi'
icon_state = ""
New(client/C)
screen_loc = "10,13"
C.screen+=src

and ive tried using obj/hud/bweapon/icon_state = "rusty", but that doesnt work, I've also tried a MILLION variants of that. Whats wrong?
so nobody knows how to solve this?
What line is the error on?
In response to Crispy (#2)
its on the obj/hud/bweapon/icon_state = "rusty" line. Basically I just need to know how to edit a variable like that from outside, like when you pick up another obj. Also, it may help that when a client connects to a mob:
new/obj/hud/bweapon(src)
In response to Mooseboy (#3)
If you're putting that line in a proc, that's the problem; that sort of construct is used to set the initial value of vars, outside of procs. If you want to refer to an object inside a proc, you need to have a variable that references it.

The easiest way is probably to give mobs a var that keeps track of that bweapon obj:

<code>mob var/obj/hud/bweapon/MyBWeapon</code>

And then assign the var to the obj when you create it, like this (instead of that last line you mentioned):

<code>src.MyBWeapon = new(src)</code>

Then when you want to change its icon_state within a proc, you can just do this:

<code>src.MyBWeapon.icon_state="rusty"</code>

Note that "src.MyBWeapon" can (usually) be shortened to just "MyBWeapon". The exception is when you make a local var, also called "MyBWeapon" (which you shouldn't really do anyway).
In response to Crispy (#4)
Thnx for your help, but it still won't work.

I understand how it works. You declare MyBWeapon, then make it equal the obj itself, so you can edit it's variables like that.

Here's basically what I have(with unrelated code removed)
<hr>
proc
givesword(swd as text)
src.MyBWeapon.icon_state = "w[swd]1"
src.MyBWeapon2.icon_state = "w[swd]2"
src.mysword.icon_state = "[swd]"

mob/var/obj/hud/bweapon/MyBWeapon
mob/var/obj/hud/bweapon2/MyBWeapon2
mob/var/obj/hud/aweapon/MyAWeapon
mob/var/obj/hud/aweapon2/MyAWeapon2
mob/var/obj/sword/mysword

obj
hud
layer = MOB_LAYER + 1//appears above mobs
icon = 'hud.dmi'
bweapon
layer = MOB_LAYER + 2
dir = NORTH
icon = 'weapons.dmi'
icon_state = "wrusty1"
New(client/C)
screen_loc = "10,13"
C.screen+=src
aweapon
layer = MOB_LAYER + 2
dir = NORTH
icon = 'weapons.dmi'
icon_state = ""
New(client/C)
screen_loc = "12,13"
bweapon2
layer = MOB_LAYER + 2
dir = NORTH
icon = 'weapons.dmi'
icon_state = "wrusty2"
New(client/C)
screen_loc = "10,14"
C.screen+=src
aweapon2
layer = MOB_LAYER + 2
dir = NORTH
icon = 'weapons.dmi'
icon_state = ""
New(client/C)
screen_loc = "12,14"

client/New()
. = ..()
src.MyAWeapon = new/obj/hud/aweapon(src)
src.MyAWeapon2 = new/obj/hud/aweapon2(src)
src.MyBWeapon = new/obj/hud/bweapon(src)
src.MyBWeapon2 = new/obj/hud/bweapon2(src)
<hr>
And here's a listing of the errors I get:
<hr>
Mooseworld.dm:238:error:src.MyBWeapon.icon_state:undefined var
Mooseworld.dm:239:error:src.MyBWeapon2.icon_state:undefined var
Mooseworld.dm:240:error:src.mysword.icon_state:undefined var
Mooseworld.dm:510:error:src.MyAWeapon:undefined var
Mooseworld.dm:511:error:src.MyAWeapon2:undefined var
Mooseworld.dm:513:error:src.MyBWeapon:undefined var
Mooseworld.dm:514:error:src.MyBWeapon2:undefined var
<hr>
Thanks to anyone who can help.
In response to Mooseboy (#5)
not sure if this is allowed, but going for major bumpage cause I'm still having the same problems. Any help is appreciated
In response to Mooseboy (#5)
your givesword or whatever is a regular proc. Make it a mob/proc, or have it take a mob as an argument.