ID:147939
 
In my Time crisis game, You have a health hud, how do I get it to update automatically? currently I have it updating when you shoot, but it would really be nice if it did it automatically =)
heres some of the code:
proc/health()
for(var/obj/healthbar/H in usr.client.screen)
if(usr.HP == 1)
H.icon_state = "1"
if(usr.HP == 2)
H.icon_state = "2"
if(usr.HP == 3)
H.icon_state = "3"
if(usr.HP == 4)
H.icon_state = "4"
if(usr.HP == 5)
H.icon_state = "5"
if(usr.HP == 6)
H.icon_state = "6"
if(usr.HP == 7)
H.icon_state = "7"
if(usr.HP == 8)
H.icon_state = "8"
if(usr.HP == 9)
H.icon_state = "9"
if(usr.HP == 10)
H.icon_state = "10"
if(usr.HP == 0)
H.icon_state = "0"

This Is The Proc in need it to loop through, can someone please help me? I tried telling it to run itself at the end of the proc, but it said never ending loops wheren't allowed, please, please, please, please, please, please, please, please, Help me!
  • No put usr in proc.

  • No use ton of if statements. Use H.icon_state="[HP]".

  • Just call health() when HP change.

    Ungh.

    Lummox JR
In response to Lummox JR (#1)
how would I code that?
client.healthchange?
where would I put it?
?????????
In response to DarkCampainger (#2)
DarkCampainger wrote:
how would I code that?
client.healthchange?
where would I put it?
?????????

I don't recall mentioning anything called client.healthchange.

I said just call the mob's health() proc whenever HP changes. That would be whenever you gain health, lose health, or initialize the HUD. Continuous updating would be a bad, bad idea.

Lummox JR
In response to DarkCampainger (#2)
DarkCampainger wrote:
how would I code that?
client.healthchange?
where would I put it?
?????????

your proc isnt even a client proc, its just a proc for the world not for a mob or client (orwhatever you want it to be)
Look at these two ways of using spawn...
// Way 1

proc/health()
spawn while(1)
// ...statements...
sleep(10) // Loop Delay

// Way 2

Login()
spawn while(1)
health()
sleep(10) //Loop Delay
proc/health()
// ...statements...

Spawn can be very usefull. Use it to make background procedures and more.
In response to Yota (#5)
I repeat: Calling health() on a loop is a truly bad idea. It only need be called when HP changes.

Lummox JR
In response to Lummox JR (#6)
I tried putting in the Badguy attack code before.... and I got alot of errors...... but I'll try it again and pray for results.
In response to DarkCampainger (#7)
runtime error: Cannot read null.client
proc name: health (/proc/health)
source file: TimeCrisis.dm,1490
usr: DarkCampainger (/mob/PC)
src: null
call stack:
health()
DarkCampainger (/mob/PC): Login()

darn, so close........ =(
I'm guessing this is from when I told It to run at login
In response to DarkCampainger (#8)
hmmm, I got it to work at login, but now I get this error from when the badguys attack:

runtime error: Cannot read null.screen
proc name: health (/proc/health)
source file: TimeCrisis.dm,1489
usr: Lvl3bg (/mob/bg/lvl3bgo)
src: null
call stack:
health(DarkCampainger (/mob/PC))
Lvl3bg (/mob/bg/lvl3bgo): Attack(DarkCampainger (/mob/PC))
Lvl3bg (/mob/bg/lvl3bgo): Bump(DarkCampainger (/mob/PC))

I know whats wrong, it's the usr in the proc (your gonna be mad I guess >< ) but thats the only way I could get it to work =(
but I made the proc shorter like Lummox Jr said
=)Good And Bad=(
In response to DarkCampainger (#9)
I got It To WOrk!
all I had to do was make 2 seperate proc, 1 for when you shoot/login, and 1 for when the badguys attack =)

Thanks Everyone!