HUD Var Tiles not drawing correctly [Solved]

JeffPack

New member
So my game has people you need to rescue. They are marked as a game object pickup. The idea is the var tiles hud element is supposed to decrease just like the health meter works.
Capture.PNG

Here is the code that the pickup runs:
Code:
	AddValue #$07, myScore, #$02, #$02
	LDA #$01
	STA hudElementTilesToLoad
	LDA DrawHudBytes
	ORA #HUD_myScore
	STA DrawHudBytes
	
	LDA mySurvivors
	CLC
	CMP #$00
	BEQ noMoreSurvivors
	
removeSurvivor:
	SEC	
	SBC #$01
	STA mySurvivors
	STA hudElementTilesToLoad
	LDA #$00
	STA hudElementTilesMax
	LDA DrawHudBytes
	ORA #HUD_mySurvivors
	STA DrawHudBytes
	
noMoreSurvivors:
	TriggerScreen screenType
	PlaySound #SFX_GET_COIN

But here is the result I get when the survivor is picked up
Capture1.PNG

But when I transition over to a new screen everything is as it should be
Capture2.PNG

Anyone have any ideas what I'm doing wrong here?
 

dale_coop

Moderator
Staff member
You have this problem, because you can't update 2 HUD variables at the same time, with the current code.
I think Joe explain something about that , and a technique that could be used. But Can't find it.
 

dale_coop

Moderator
Staff member
Here, Chronosv2 had the same question... and found a solution:
http://nesmakers.com/viewtopic.php?f=23&t=725&p=4618#p4618
 

JeffPack

New member
Ok thanks for the link. I changed my code to the following so I'm only updating one element:

Code:
	LDA mySurvivors
	CLC
	CMP #$00
	BEQ noMoreSurvivors
	
removeSurvivor:
	SEC	
	SBC #$01
	STA mySurvivors
	
noMoreSurvivors:
	TriggerScreen screenType
	PlaySound #SFX_GET_COIN	
	
	LDA mySurvivors
	STA hudElementTilesToLoad
	LDA #$00
	STA hudElementTilesMax
	LDA DrawHudBytes
	ORA #HUD_mySurvivors
	STA DrawHudBytes

Unfortunately I have the same problem:
Glitch.PNG
 

JeffPack

New member
I found out if I change the y position of the hud element to anything more than 3 it glitches. Anything less than that and it works fine! WTF?
 

dale_coop

Moderator
Staff member
Your code seems correct.
I think something else make your HUD glitch.

Where did you write your code? a new script? or somewhere in the middle of another one?
 

JeffPack

New member
dale_coop said:
Your code seems correct.
I think something else make your HUD glitch.

Where did you write your code? a new script? or somewhere in the middle of another one?

The survivor is a pickup in the "currency" spot
This code replaces the Increase_Currency.asm
 

chronosv2

New member
I believe that's a known issue, but I have no idea if there's any info on a fix. It seems that a HUD 2 blocks tall is the ideal setting right now.
As for score and survivors, I think even though my code was designed for longer bars it could work in this case. You'd need to make sure Score and Survivors are next to each other on the element list (if score is Element 3, Survivors must be element 4, but you don't need the LongHUDBars code file for your case since you don't need to calculate a 16-wide bar.

Before you do any of this, please make a backup of your project and the code in the routines folder. If I overlooked something (which I don't think I did) I don't want it breaking your entire project.
Download the HudUpdate_LongHudSupport.asm script from my GitHub repository ( https://github.com/chronosv2/NESMaker_Public_Code_Repository/tree/master/LongVarHUD ), and put it somewhere like UserScripts
Go into Project Settings -> Script Settings and create a new define:
Name: Update Two HUDs
Define: SCR_LONGHUD
Script: [wherever-you-put-the-file]\HudUpdate_LongHudSupport.asm

Go into Project Settings -> User Variables and create a variable -- capitalization is important.
Name: LongHudVar
Default Value: 0

Then your original HUD code:
Code:
AddValue #$07, myScore, #$02, #$02
;	LDA #$01
;	STA hudElementTilesToLoad
	LDA DrawHudBytes
	ORA #HUD_myScore
	STA DrawHudBytes
	
	LDA mySurvivors
	CLC
	CMP #$00
	BEQ noMoreSurvivors
	
removeSurvivor:
	SEC	
	SBC #$01
	STA mySurvivors
	STA LongHudVar ;This code here is what will update your Survivor count next frame.
	STA hudElementTilesToLoad
	LDA #$00
	STA hudElementTilesMax
	LDA DrawHudBytes
	ORA #HUD_mySurvivors
	STA DrawHudBytes

noMoreSurvivors:

The last step is modifying a system file, but it's got to be done, and an update that changes HUD code might undo this:
We need to make a change to the HandleHudData.asm file in GameEngineData\Routines\System
Go to line 471. Hit enter at the start of the line so that 471 is blank and 472 is "LDA #$00". Place this line at Line 471:
Code:
IFDEF SCR_LONGHUD
  .include SCR_LONGHUD  ;This DEFINE is used to implement long Var Tile support.
ENDIF
The IFDEF stuff makes sure we don't break the HUD for any other projects.

All of that done having two HUD items update in one script should work just fine.
 

JeffPack

New member
chronosv2 said:
I believe that's a known issue, but I have no idea if there's any info on a fix. It seems that a HUD 2 blocks tall is the ideal setting right now.
As for score and survivors, I think even though my code was designed for longer bars it could work in this case. You'd need to make sure Score and Survivors are next to each other on the element list (if score is Element 3, Survivors must be element 4, but you don't need the LongHUDBars code file for your case since you don't need to calculate a 16-wide bar.
...

Yes I was looking at your code chronosv2. Fantastic work. After moving my HUD element up one row to avoid the glitch I was able to get score and survivor count update working with the following code

Code:
	AddValue #$07, myScore, #$02, #$02
	
	LDA mySurvivors
	CLC
	CMP #$00
	BEQ noMoreSurvivors

	SEC	
	SBC #$01
	STA mySurvivors
	
noMoreSurvivors:
	TriggerScreen screenType
	PlaySound #SFX_GET_COIN	
	
	LDA mySurvivors
	STA hudElementTilesToLoad
	LDA #$00
	STA hudElementTilesMax
	LDA DrawHudBytes
	ORA #HUD_mySurvivors
	ORA #HUD_myScore
	STA DrawHudBytes
 

JeffPack

New member
chronosv2 said:
Oh, then that leads me to understand that only varTiles suffer the one-per-update rule! Awesome!

Yeah that would absolutely make sense because of the following:
Code:
LDA mySurvivors
STA hudElementTilesToLoad

hudElementTilesToLoad probably needs to be updated per var tile element
 

chronosv2

New member
Well that's neat. There's something completely stupid I've got to test now.
8 HUD variables. 1 is a bar, the rest are numbers.


Well that's really good to know! You CAN update all 8 elements in one script if you don't mind being able to see the refresh!
 

JeffPack

New member
chronosv2 said:
Well that's neat. There's something completely stupid I've got to test now.
8 HUD variables. 1 is a bar, the rest are numbers.
Silly.gif

Well that's really good to know! You CAN update all 8 elements in one script if you don't mind being able to see the refresh!

Sweet! Yeah honestly I consider the refresh a really trivial compromise. Good stuff! Now we know...
...
...
and knowing is half the battle.
 

chronosv2

New member
Indeed! And nice reference. :lol:
If this problem is solved do you mind editing your first post and putting [Solved] or something like that at the end of the Subject?
 
Top Bottom