ID:148786
 
I am trying to create a HUD object to display the player's health, and am unsure what this means.
obj/Health
icon = 'health.dmi'
layer= MOB_LAYER+1
if(usr.HP == 100)
icon_state = "100"
else if(usr.HP == 75)
icon_state = "75"
else if(usr.HP == 50)
icon_state = "50"
else if(usr.HP == 25)
icon_state = "25"
else if(usr.HP == 0)
icon_state = "0"


The entire object has errors.

The errors are:

loading RoboWars.dme
loading Macro.dms
hud.dm:4:error:usr.HP:duplicate definition
hud.dm:4:error:100:duplicate definition
hud.dm:4:error:== :instruction not allowed here
hud.dm:4:error::empty type name (indentation error?)
hud.dm:5:error::empty type name (indentation error?)
hud.dm:6:error:usr.HP:duplicate definition
hud.dm:6:error:75:duplicate definition
hud.dm:6:error:== :instruction not allowed here
hud.dm:6:error::empty type name (indentation error?)
hud.dm:7:error::empty type name (indentation error?)
hud.dm:8:error:usr.HP:duplicate definition
hud.dm:8:error:50:duplicate definition
hud.dm:8:error:== :instruction not allowed here
hud.dm:8:error::empty type name (indentation error?)
hud.dm:9:error::empty type name (indentation error?)
hud.dm:10:error:usr.HP:duplicate definition
hud.dm:10:error:25:duplicate definition
hud.dm:10:error:== :instruction not allowed here
hud.dm:10:error::empty type name (indentation error?)
hud.dm:11:error::empty type name (indentation error?)
hud.dm:12:error:usr.HP:duplicate definition
hud.dm:12:error:0:duplicate definition
hud.dm:12:error:== :instruction not allowed here
hud.dm:12:error::empty type name (indentation error?)
hud.dm:13:error::empty type name (indentation error?)

RoboWars.dmb - 25 errors, 0 warnings (double-click on an error to jump to it)
if statements need to be contained within a proc. The make no sense placed where you have them directly under an object definition.
In response to Skysaw
lol, stupid me.
In response to Drafonis
Now it won't display the HUD item.
In response to Drafonis
Drafonis wrote:
Now it won't display the HUD item.

One of the reasons it's not displaying is that you made the mistake of using == to check a value when you really needed a range of values, as would be found with >= and <=:
if(usr.HP == 100)
icon_state = "100"
else if(usr.HP == 75)
icon_state = "75"
else if(usr.HP == 50)
icon_state = "50"
else if(usr.HP == 25)
icon_state = "25"
else if(usr.HP == 0)
icon_state = "0"
Although I could show you how to do ranges, the entire if/else setup here is deeply misguided. You should be doing this instead:
icon_state = "[round(owner.mob.HP,25)]"
Instantly rounded to the nearest 25. Notice I used owner.mob instead of usr: Details follow.

The second problem is that you have usr scattered all over here. usr should have zero place in a HUD. In fact, if you use usr anywhere outside of a verb, it's almost always an indication that you've massively frelled up your code. (It's legitimate in a proc that's only ever called by a verb or player action, but even there I'd say it's safer to use something else.) When you create a HUD object, pass a reference to the client who will see it, and then store that for future reference:
obj/HUDobj
var/client/owner

New(client/C)
owner=C
C.screen+=src

Del()
if(owner) owner.screen-=src
..()
Any reference to the mob who controls this HUD will be owner.mob.

Lummox JR