Buggy health display

Imagaryboy

New member
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?
 

dale_coop

Moderator
Staff member
It could be related to that issue:
http://nesmakers.com/viewtopic.php?p=5340#p5340
And maybe this issue too:
http://nesmakers.com/viewtopic.php?f=23&t=820&p=5158#p5151
 

clay

New member
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:
;;; 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?
 

dale_coop

Moderator
Staff member
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:
	CMP #$04
to:
Code:
	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:
			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			STA hudElementTilesToLoad
And modify like this (adding a line of code):
Code:
			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:
DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
And modify like this :
Code:
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 ;)
 

dale_coop

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

Capture-d-cran-2019-08-19-21-57-42.png
 

clay

New member
I made the changes, but the HUD is still misbehaving :?
 

Attachments

  • health7.PNG
    health7.PNG
    17.3 KB · Views: 2,353
  • health6.PNG
    health6.PNG
    9.5 KB · Views: 2,352
  • health5.PNG
    health5.PNG
    6.9 KB · Views: 2,353
  • health4.PNG
    health4.PNG
    56.9 KB · Views: 2,353
  • health3.PNG
    health3.PNG
    27.8 KB · Views: 2,353
  • health2.PNG
    health2.PNG
    27.2 KB · Views: 2,353

dale_coop

Moderator
Staff member
With all those modifications... you still have all of your issues?
Or just some of them remain?
 

clay

New member
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.
 

dale_coop

Moderator
Staff member
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)
 

clay

New member
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.3 MB · Views: 82

dale_coop

Moderator
Staff member
Ok...
I found the cause of your issue. I think you added a block of code at the end of the Handle Monster Drop, comment out all that code (after the ";;; added script" line).
And I think your project will work again, correctly ;)
 
Top Bottom