Buggy health display

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
Imagaryboy
Posts: 18
Joined: Mon Aug 20, 2018 9:05 am
Location: Cologne

Buggy health display

Post by Imagaryboy » Thu Sep 06, 2018 7:59 am

My player has 5 HP which are shown in the hud. Every time the player gets hit by an enemy, it subtracts one HP which can also be observed in the hud. So far so good.
But when the players HP reaches 0, the last HP doesn't disappear from the hud but the player still dies. When the game starts from the beginning, the hud still shows only the last HP but internally thinks the health got replenished and starts counting from 5 again, making the HP display in the hud buggy.

Can someone help me fix this?
User avatar
dale_coop
Posts: 5408
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Buggy health display

Post by dale_coop » Thu Sep 06, 2018 10:00 am

-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
clay
Posts: 9
Joined: Wed Aug 14, 2019 4:21 am

Re: Buggy health display

Post by clay » Mon Aug 19, 2019 7:52 pm

Dale, thanks for all your help so far! I'm also dealing with HUD health issues and I can't find a fix in the forums.

HUD starting health=5, max health=5, player max health=5. HUD displays health, keys, currency. Everything but health works fine. I'm testing on screens with no triggers.

Always, one health pickup will max out my health.
Sometimes, when I kill a monster, my health recovers to max health (instantly, without a drop).
Sometimes, when I kill a monster, my health exceeds the max by 1-3.
Sometimes, when I'm hurt, I lose 1-4 health (monster strength is at default:0).
Rarely, when I'm hurt i receive more than 1 damage, the HUD shows 1 heart, then four blanks, then four hearts. the next attack kills me
Sometimes, when I change screens I lose 1-3 health.

I'm using modified Powerup_Health script:

Code: Select all

;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
    LDA myHealth
    CLC
    ADC #$01
    CMP #$04
    
    
    TXA
    STA tempx
    ;;;you may want to test against a MAX HEALTH.
    ;;; this could be a static number in which case you could just check against that number
    ;;; or it could be a variable you set up which may change as you go through the game.
    inc myHealth
    LDA myHealth
    
    LDX player1_object
    STA Object_health,x

    ;;; we also need to set up the routine to update the HUD
    ;; for this to work right, health must be a "blank-then-draw" type element.
    STA hudElementTilesToLoad
        LDA #$00
        STA hudElementTilesMax
        ; LDA DrawHudBytes
        ; ORA #HUD_myHealth
        ; STA DrawHudBytes
    UpdateHud HUD_myHealth
    LDX tempx

;;; we also need to set up the routine to update the HUD
    ;; for this to work right, health must be a "blank-then-draw" type element.
    STA hudElementTilesToLoad
    LDA #$00
    STA hudElementTilesMax
    LDA DrawHudBytes
    ORA #HUD_myHealth  ;;  <<--- HERE Your Pickup-related Variable
    STA DrawHudBytes
How should I approach this?
User avatar
dale_coop
Posts: 5408
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Buggy health display

Post by dale_coop » Mon Aug 19, 2019 8:03 pm

For the Powerup_IncreaseHealth script, it will not work... this one is an old script. It's not really compatible.
I'd suggest to get back the original one (you made a copy? or get it from the nesmaker zip file). And just modify the

Code: Select all

	CMP #$04
to:

Code: Select all

	CMP #$06

Then, you need to fix some current issues (natively), in NESmaker, about the health HUD...
When the game starts it always shows hud MAX (eveen if the real myHealth value is lower)...

To fix that issue:
1) modify the "HandleUpdateObjects.asm" script (in the "Basic\System\" folder), around line 193, locate those lines:

Code: Select all

			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			STA hudElementTilesToLoad
And modify like this (adding a line of code):

Code: Select all

			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			LDA myHealth	;;HERE <-------- fix to start with the correct hud health
			STA hudElementTilesToLoad
1) modify the script assgined to the "Hud Element 0" element in your "Project Settings > Script Settings" (it should be the HUD_Element_Var_Image.asm script), , around line 12, locate those lines:

Code: Select all

DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
And modify like this :

Code: Select all

DoScreenOffHudUpdate:
	; LDX player1_object 	;; commented out !
	; LDA Object_health,x	;; commented out !
  	; STA myHealth	;; commented out !
	LDA myHealth	;;dale_coop: fix to start with the correct hud health
Now it should display the right health value in the HUD.

Make sure your Player's health value is "5".
You myHealth HUD variable initial value is "5"... and that your HUD element displaying myHealth has its Max value set to "5".

If you have issues, share screenshots of all that ;)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
User avatar
dale_coop
Posts: 5408
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Buggy health display

Post by dale_coop » Mon Aug 19, 2019 8:06 pm

Also, when you want to share code, use the "Full Editor & Preview" mode... and click on the [ code ] button :

Image
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
clay
Posts: 9
Joined: Wed Aug 14, 2019 4:21 am

Re: Buggy health display

Post by clay » Mon Aug 19, 2019 9:30 pm

I made the changes, but the HUD is still misbehaving :?
Attachments
health2.PNG
health2.PNG (27.24 KiB) Viewed 1819 times
health3.PNG
health3.PNG (27.85 KiB) Viewed 1819 times
health4.PNG
health4.PNG (56.91 KiB) Viewed 1819 times
health5.PNG
health5.PNG (6.93 KiB) Viewed 1819 times
health6.PNG
health6.PNG (9.55 KiB) Viewed 1819 times
health7.PNG
health7.PNG (17.32 KiB) Viewed 1819 times
User avatar
dale_coop
Posts: 5408
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Buggy health display

Post by dale_coop » Tue Aug 20, 2019 7:12 am

With all those modifications... you still have all of your issues?
Or just some of them remain?
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
clay
Posts: 9
Joined: Wed Aug 14, 2019 4:21 am

Re: Buggy health display

Post by clay » Tue Aug 20, 2019 7:43 am

I still have all previously mentioned HUD health issues. I'm going to look through my scripts to see if I made other (outdated) health pickup changes in other areas.
User avatar
dale_coop
Posts: 5408
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Buggy health display

Post by dale_coop » Tue Aug 20, 2019 8:23 am

It's not normal... you should not have any of those issues.
Could you share your NESmaker project (zipped)? I will check what's going on... (more specifically, I'd need the project .MST file,the GraphicAssets sand GameEngineData folders)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
clay
Posts: 9
Joined: Wed Aug 14, 2019 4:21 am

Re: Buggy health display

Post by clay » Tue Aug 20, 2019 4:23 pm

Here are the requested files (I'm also having an issue with the "NPC shop" asm. NPCs don't take currency into account and don't give item when purchased). Thank you so much for looking at this.
Attachments
buggy_health.zip
(9.31 MiB) Downloaded 56 times
Post Reply