Generic Timers?

SuperNatetendo

New member
Okay, something that would really help me out is some sort of way to do a timer in code. That is, I'd like to have a script that runs where I tell it to say... change action state to 3, then wait for a set amount of time, then say ... add 30 to max speed of the player.

Or maybe I want the game to store a value, wait for a time, then do a check of that value to prompt an action.

I'd just really like to be able to use a timer in code instead of every command I write to happen instantly.
 

Mugi

Member
i will once again just paste my hud's gradual HP filling code, because it's simple, and it just works.
this should be fairly easy to adapt to other usage. I added some documentation into it to make it easier to read.

for this to work, 2 variables are required: HudTimer and HudHealth. Again, adjust as necessary.

Code:
    LDA Object_health,x		; load whatever you want to do things with in here
    CMP HudHealth		; compare to it
    BCC hudhealthstore
                            	; If here, value is greater or equal
    BEQ hudhealthstore      	; If here, the value is equal
                            	; If here, player Health is greater than HudHealth. Our player (probably) picked up health recently.

    INC HudTimer		; increase timer value
    LDA HudTimer
    STA HudTimer
    AND #%00000111	        ; Will only add every 8th frame. (this timer does things once every 8 frames, adjust as necessary.)
    BNE skipaddhud		; don't execute because timer is not done.

			; below this point is what executes when timer is done.
    LDA HudHealth
    CLC
    ADC #1
hudhealthstore:
    STA HudHealth
skipaddhud:
    LDA HudHealth
    STA temp3
 
Top Bottom