What am i doing wrong with HUD vars?

FrankenGraphics

New member
Health works as expected. But if i deploy let's say myMoney or any of the UserVar_n:s, the following results are shown on screen:

Despite setting the init value to let's say 3, upon game start the value is 0.
If i move to another screen, this value is updated to 3.
If the player character gets hurt, nothing immediately shows, but if i go to another screen, that 3 is now updated to a 1 - Consistently.

Getting hurt shouldn't affect these values at all.
They shouldn't get updated at new screens only.
I haven't written any custom code to tie them up yet.

What is causing this behaviour? I'm using the adventure module in 4.1


where i am at the moment:
i'm going to try to have a game start flag let the values increase to max in a staggered fashion over time, and one at a time up to the max to see if i can force the updates that way.
i'm still not sure why being hurt sets all vars to 1 though.
 

dale_coop

Moderator
Staff member
The rule is (should be) HUD always display the value of the HUD variables.
If you set your "myHealth" HUD var with an intiial value of "3", it should display "3" when you start the game.... then when your player gets hurt (the hurt script), the value if myHealth decreases by 1, so the HUD should display that value.
Same for any other HUD var.

But... there are some issues in the engine....
For the correctly myHealth at start, you need to modify the HandleUpdateObjects.asm script (in the Routines\Basic\System\ folder), around line 192...
From this:
Code:
			BEQ +
			STA hudElementTilesToLoad
To this:
Code:
			BEQ +
			LDA myHealth
			STA hudElementTilesToLoad

(Also check that your player object's health property is set correclty... should be the same value than your HUD myHealth variable initial value).
 

FrankenGraphics

New member
my issue isn't with myHealth though; it's the only HUD var that seems to work correctly. it's with every other variable except myHealth!

I use a UserVar_5 for something i call stamina which determines for how long the player can sprint, if the player is able to sneak at all, and also provides a base speed modifier. . It has a starting value of 3, max of 7. Right now it is not hooked up to those custom game functions so it should just read a solid 3 at all times. If i get hurt, userVar_5 gets reduced on the next screen update. <false observation>Same with score, apparently. I tested setting the score to 5 at game start just to see. And apparently it is set back to 0 if the player gets hurt on next screen update..</false>

Edit:
Wait, strike the part about myScore.. that seems to have to do with two certain screens doing something to overwrite the tiles. There's nothing in the level layout to suggest why. But it's a whole other error.

it's still true for every other variable though!
 

dale_coop

Moderator
Staff member
I see..
It's because the "0:var tiles" HUD elements updates are harcoded, it works only for myhealth (and if you keep it as 2nd hud element).

Take a look at the "HUD_Element_Var_Image.asm" script (in your "Routines\Basic\System\HudElementScripts" folder), line 12, you will find:
Code:
DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
	
	STA hudElementTilesToLoad

THAT means all the var images (means "0:var tiles") display in fact the myHealth value!


For your game, I would suggest to duplicate this script, rename for example "HUD_Element_Var_Image_withStamina.asm", replacing the 12th lines with that:
Code:
DoScreenOffHudUpdate:
	;; if updating the 2nd hud element:
	LDA updateHUD_active
	AND #%01000000
	BEQ +
		LDX player1_object
		LDA Object_health,x
		STA myHealth
		JMP ++
	+
	;; if updating the 5th hud element:
	LDA updateHUD_active
	AND #%00000100
	BEQ +
		LDA myStamina
		JMP ++
	+
	LDA #$00
	++

	STA hudElementTilesToLoad


And in the "Peoject Settigns > Script Settings" dialog, assign that "HUD_Element_Var_Image_withStamina.asm" script to the "Hud Element 0" (that corresponds to the var tiles display script).
 

FrankenGraphics

New member
Thanks!! I see this is present in assets, text strings and numbers - just not in varTiles. I guess it's a good thing to keep an eye out for if anything else seems odd - all possible things that you can seem to do in the GUI might not necessarily represent that it's fully supported in the codebase as is!
 
Top Bottom