HUD doesn't update health upon death

Having trouble compiling code? Getting an unexpected error? Player not appearing on screen? Seeking answers on how to do a particular thing? This is the forum you're looking for, to ask other NESmaker users for assistance.
User avatar
Redherring32
Posts: 92
Joined: Sat Aug 11, 2018 2:48 pm
Location: Usa

Re: HUD doesn't update health upon death

Post by Redherring32 » Fri Nov 09, 2018 1:31 am

It works! The last heart doesn't go away,
But the hearts reset fine.
User avatar
chronosv2
Posts: 204
Joined: Wed Aug 08, 2018 9:30 pm
Location: KY, USA
Contact:

Re: HUD doesn't update health upon death

Post by chronosv2 » Fri Nov 09, 2018 1:52 am

I think that's because the Hurt code doesn't actually update the myHealth variable if the death condition is true. You could solve it by storing the 0 in myHealth and updating the HUD before handling death.
User avatar
Redherring32
Posts: 92
Joined: Sat Aug 11, 2018 2:48 pm
Location: Usa

Re: HUD doesn't update health upon death

Post by Redherring32 » Fri Nov 09, 2018 3:42 am

chronosv2 wrote:
Fri Nov 09, 2018 1:52 am
I think that's because the Hurt code doesn't actually update the myHealth variable if the death condition is true. You could solve it by storing the 0 in myHealth and updating the HUD before handling death.
How would I do that?
I know 0 Assembly, so I'm completely clueless.


-Edit To clarify, all 3 hearts go down on the first death, but the rest of the times my player dies the last heart stays.
User avatar
chronosv2
Posts: 204
Joined: Wed Aug 08, 2018 9:30 pm
Location: KY, USA
Contact:

Re: HUD doesn't update health upon death

Post by chronosv2 » Fri Nov 09, 2018 5:11 am

Ah, I didn't realize it worked fine on the first attempt and then not on any others. Hm.

I was originally thinking to move the block of code in Adventure_HandlePlayerHurt.asm or Platform_HandlePlayerHurt.asm

Code: Select all

	STA Object_health,x
	STA myHealth

	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
above

Code: Select all

	CMP #$01
	BCS notPlayerDeath
and add

Code: Select all

	LDA myHealth
between them so it ultimately looks like this (Line 36, the line immediately above this is "SBC #$01"):

Code: Select all

	STA Object_health,x
	STA myHealth

	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
	LDA myHealth
	CMP #$01
	BCS notPlayerDeath
	.include SCR_HANDLE_PLAYER_DEATH
	JMP doneWithPlayerHurt
notPlayerDeath:
	PlaySound #SFX_PLAYER_HURT  ;; If this is commented out in the script you're editing (starts with ";") you should keep it commented out.
doneWithPlayerHurt:
I think that should do it.
As always, back up the file before you make any changes, just to be safe. I think this should work, but I haven't had any opportunity to test it.
User avatar
Redherring32
Posts: 92
Joined: Sat Aug 11, 2018 2:48 pm
Location: Usa

Re: HUD doesn't update health upon death

Post by Redherring32 » Fri Nov 09, 2018 5:22 am

That worked!!!!
Thanks a bunch, I owe you one!
User avatar
chronosv2
Posts: 204
Joined: Wed Aug 08, 2018 9:30 pm
Location: KY, USA
Contact:

Re: HUD doesn't update health upon death

Post by chronosv2 » Fri Nov 09, 2018 5:48 am

I'm glad to be of help. I'm learning ASM myself, and using what I've learned to make tutorials for others to follow. I've made some missteps along the way so far but I'm glad to hear that fix did the trick. I was a little concerned moving the HUD Update code up might cause a conflict, but that's why I suggested backing up.

In my opinion, it's a lot of fun once you really get into it. I've got some scripts in the works for 4.1.0, and I love writing in this old programming language designed for a 1975 processor.
User avatar
Redherring32
Posts: 92
Joined: Sat Aug 11, 2018 2:48 pm
Location: Usa

Re: HUD doesn't update health upon death

Post by Redherring32 » Fri Nov 09, 2018 5:52 am

I'll try learning it,
but JavaScript was hard enough... :oops:
Post Reply