Is there something wrong with the HUD handling in NESmaker?

baardbi

Well-known member
First things first. I'm using NESmaker 4.1.5 with the patch BASIC_021019, and I am using the Simple Platform module.

I'm just wondering if I'm doing something very wrong, or if there are some bugs in the HUD handling.

When I start my game only my health variable is updated in the HUD. No lives are showing, despite I have three lives set as the initial value. Score is there, except for the last digit that is not showing. The enemy health is blank, even though I have set initial value to 8:

hud1.png


When I go to the next screen the enemy health and the lives are updated in the HUD. The last digit of score is still missing:

hud2.png


When I kill my first enemy the last digit of the score comes to life:

hud3.png


When I lose health the enemy health (boss health) matches my health when I go to the next screen (even though I haven't met the boss):

hud4.png


And lastly when I lose a life the HUD still shows three lives (it never changes), even though it's game over after three deaths...

My variable types are VarTiles except Score which is Number.

My HUD setup looks like this:

hud5.png


Can someone please tell me what's going on?

PS! I have tried to fix it by using the instructions from this post: http://nesmakers.com/viewtopic.php?f=48&t=2308&hilit=hud+not+updating+correctly , but I couldn't complete it because the line numbers in MainASM.asm and HandleUpdateObjects.asm didn't contain the lines Rustocrat had posted. I thought maybe this is because I'm using the patch BASIC_021019.
 

baardbi

Well-known member
Sure thing. I guess the most relevant would be HandleHudData.asm. I have to mention that I am using mostly stock scripts (especially when it comes to the HUD handling).

Here is HandleHudData.asm:

Code:
HandleHudData:

	LDA textboxHandler
	BEQ +
	RTS
+
	;; we may have to test to see if any other tiles are updating this frame.
	;; and skip if there are tiles updating.
	;; NOW let's find which element might be updating.
	LDA ActivateHudUpdate
	BEQ + ;; hud is not currently being updated
	;; HUD IS being currently activated
	JMP UpdateHudTiles
+ 
	;;;;;;;;;;;;;;;;;; FIRST, reset values:
	LDA #$00
	STA updateCHR_counter
	STA updateCHR_offset
	
;;; CHECK FIRST ELEMENT
	LDA DrawHudBytes
	AND #%10000000 
	BEQ +
	;; do first element
	LDY #$00
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_0_STRING
	STA updateHUD_STRING
	LDA #BOX_0_ASSET_0_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_0_STRING
	JMP UpdateHudTiles
+
;;; CHECK SECOND ELEMENT
	LDA DrawHudBytes
	AND #%01000000 
	BEQ +
	;; do second element
	LDY #$01
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_1_STRING
	STA updateHUD_STRING
	LDA #BOX_0_ASSET_1_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_1_STRING
	JMP UpdateHudTiles
+
+++++
;;; CHECK THIRD ELEMENT
	LDA DrawHudBytes
	AND #%00100000 
	BEQ +
	;; do third element
	LDY #$02
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_2_STRING
	STA updateHUD_STRING
	LDA #BOX_0_ASSET_2_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_2_STRING
	JMP UpdateHudTiles
+
;;; CHECK FOURTH ELEMENT
	LDA DrawHudBytes
	AND #%00010000
	BEQ +
	;; do fourth element
	LDY #$03
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_3_STRING
	STA updateHUD_STRING
	LDA #BOX_0_ASSET_3_STRING
		LDA #BOX_0_ASSET_3_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_3_STRING
	JMP UpdateHudTiles
+
;;; CHECK FIFTH ELEMENT
	LDA DrawHudBytes
	AND #%00001000 
	BEQ +
	;; do fifth element
	LDY #$04
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_4_STRING
	STA updateHUD_STRING
		LDA #BOX_0_ASSET_4_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_4_STRING
	JMP UpdateHudTiles
+
;;; CHECK SIXTH ELEMENT
	LDA DrawHudBytes
	AND #%00000100 
	BEQ +
	;; do sixth element
	LDY #$05
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_5_STRING
	STA updateHUD_STRING	
	LDA #BOX_0_ASSET_5_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_5_STRING
	JMP UpdateHudTiles
	
+
;;; CHECK SEVENTH ELEMENT
	LDA DrawHudBytes
	AND #%00000010
	BEQ +
	;; do seventh element
	LDY #$06
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_6_STRING
	STA updateHUD_STRING
		LDA #BOX_0_ASSET_6_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_6_STRING
	JMP UpdateHudTiles
+
;;; CHECK EIGHTH ELEMENT
	LDA DrawHudBytes
	AND #%00000001 
	BEQ +
	;; do eigthth element.
	LDY #$07
	JSR LoadHudElementInfo
	LDA #BOX_0_ASSET_7_STRING
	STA updateHUD_STRING
		LDA #BOX_0_ASSET_7_IMAGE
	STA updateHUD_IMAGE
	HudUpdateForNumericDisplay #BOX_0_ASSET_7_STRING
	JMP UpdateHudTiles
+
	
	;; end of checking element bits.
	RTS
	
	
	
UpdateHudTiles:
	
	;;; one of the hud bits was flipped.
	;;; now we have all the necessary data to do the update
	;;; FIRST check the type of asset.
	LDA updateHUD_ASSET_TYPE
	BEQ + ;; is not zero asset type
	JMP notHudElement0
+
	;;;; generally, this is for the Var Image type.
	.include SCR_HUD_ELEMENT_0
	;;; rts is in the script
notHudElement0:
	CMP #$01
	BEQ +
	JMP notHudElement1
+

	.include SCR_HUD_ELEMENT_1
	;; rts is in the script
notHudElement1:
	CMP #$02
	BEQ +
	JMP notHudElement2
+
	.include SCR_HUD_ELEMENT_2
	;; rts is in the script
notHudElement2:
	;;; elements 1 and 2 have no mid-frame updates.
	CMP #$03
	BEQ +
	JMP notHudElelement3
+
	.include SCR_HUD_ELEMENT_3 
	;;; rts is in the script
	
notHudElelement3:

HandleHudData_direct:


SkipHandleHudData:

	RTS
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
LoadHudElementInfo:
	;;; hud element loaded into y.
	LDA HudActive,y
	STA updateHUD_active
	LDA HudInverse,y
	STA updateHUD_inverse
	LDA HudAssetTypes,y
	STA updateHUD_ASSET_TYPE
	LDA HudAssetX,y
	STA updateHUD_ASSET_X
	LDA HudAssetY,y
	STA updateHUD_ASSET_Y
	;LDA HudImage,y
	;STA updateHUD_IMAGE
	LDA HudBlank,y
	STA updateHUD_BLANK
	LDA HudRow,y
	STA updateHUD_ROW
	LDA HudColumn,y
	STA updateHUD_COLUMN
	LDA HudMaxValue,y
	STA hudElementTilesFull
	RTS
	
	
	
	
	
GetHudDrawPositionAndOffset:
	;; keep in mind, a HUD will always be in the first nametable.
	LDA #BOX_0_ORIGIN_X
	STA tileX
	LDA #BOX_0_ORIGIN_Y
	STA tileY 
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	JSR coordinatesToMetaNametableValue
	;; establishes updateNT_pos and updateNT_pos+1
	;;; FIRST, IF this has been tripped, blank all of the values
	LDA updateHUD_ASSET_Y
	ASL
	ASL
	ASL
	ASL
	ASL
	STA temp
	ORA updateHUD_ASSET_X
	STA temp
	
	LDA updateHUD_ASSET_Y
	LSR 
	LSR
	
	STA temp1
	
	LDA updateNT_pos 
	CLC
	ADC temp
	CLC
	ADC updateHUD_offset
	STA updateHUD_fire_Address_Lo
	LDA updateNT_pos+1
	ADC temp1
	STA updateHUD_fire_Address_Hi
	RTS
 

baardbi

Well-known member
And here is the hudVarInits.asm:

Code:
;; *************** hudVarInits.asm ***************
;; User var init export. mandag 10. februar 2020 07:30:40

LDA #0 ; UserVar_0
STA healthText
LDA #8 ; UserVar_1
STA myHealth
LDA #0 ; UserVar_2
STA myScore
LDA #0 ; UserVar_2
STA myScore+1
LDA #0 ; UserVar_2
STA myScore+2
LDA #0 ; UserVar_2
STA myScore+3
LDA #0 ; UserVar_3
STA myScoreText
LDA #0 ; UserVar_4
STA UserVar_4
LDA #3 ; UserVar_5
STA myLives
LDA #0 ; UserVar_6
STA myEnemyText
LDA #8 ; UserVar_7
STA myEnemy

;; UserDefined var init export. mandag 10. februar 2020 07:30:40

LDA #0 ; User Defined Var 0
STA ignoreControls
LDA #0 ; User Defined Var 1
STA mySwitches
 

dale_coop

Moderator
Staff member
In the default "BASE_something" modules, there is a "bug" with the health when starting the game. The health hud is incorrect in the first screen loaded (when your player moves to another screen, the health displayes correctly).

You could try fixing 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

2/ Modify the script assigned 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 this block of code:
Code:
DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
And modify to be 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
 

baardbi

Well-known member
Great! Thanks Dale. Now I need to fix the other HUD variables acting strange. Maybe I can use some of these fixes for that as well.
 
Top Bottom