Problems with default health powerup

timmythetrtl

New member
I'm currently trying to get more familiar with the program, and right now I'm working with the 20 minute adventure tutorial. I tried using the Powerup_IncreaseHealth script that is found in Basic\ModuleScripts\PowerUpCode in order to create a health pickup, and for the most part it works, however when I'm at full health it reverts my health back to 1.

I tried messing with the script and found that the code that is supposed to skip process that increases health only works with values less then 5 (my max health for my game). I've also tried decreasing max health to 4, but it didn't solve anything.

Has anyone else had these issues?
 

baardbi

Well-known member
Yes. I had this issue as well. I had to modify the default script. Since it adds 1 before it checks max value, I changed it to check the max value (8 in my case) before it does anything else. So if the health in my game is already maxed out (8), I skip the increase health code.

My script looks like this:

Code:
;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
    LDA myHealth
    CMP #$08 ;<----- Compares to max health value
	
    BEQ skipGettingHealth

	CLC
    ADC #$01
    
    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
    
	PlaySound #SND_HEALTH_PICKUP
skipGettingHealth:
 

NeoBenj

Member
Hey there,

Also compare the value baardi refered to, with the value you entered in the HUD section of the engine. (HUDElements => Max Value)
 
Top Bottom