probem with some code i wrote(new to coding)

Logana

Well-known member
okay so I attempted to write some code that would set the players hp too 4, a replacement for the place holder pickup script which did nothing but I couldn't figure out how to update the Hud and
it made the play forever at four hp so idk again I'm new to code here it is
Code:
;small code i tried to wright that would just reset the players health to 4
		STA myHealth
		LDA #$04
;im new to code like really new so the main problem is that it would make the caracter stick at 4 hp, forever
;also the hud wount update, im wondering if anyone can help, again im new
 

CutterCross

Active member
You have the LDA and STA statements reversed. You're storing whatever value was in the Accumulator at that time into myHealth, which is also a HUD variable, and not your actual object's health variable.
You'd want to do something like this:

Code:
TXA		;;we don't want the x register to be corrupted if its not the player object, so we push it to the stack to overwrite it with the player object
PHA			;;of course, depending on where you put this code that may not be needed.
LDX player1_object
LDA #$04
STA Object_health,x		;;actual player health variable
STA myHealth			;;HUD variable representing player health
PLA		;;restoring what was previously in X from the stack
TAX

;;;;then update your HUD element

UpdateHudElement #$00	;;assuming myHealth is the 1st HUD element AND you're using a background HUD.
 
Top Bottom