SOLVED (4.5.9.) Countdown Timer in Maze Module

5kids2feed

Well-known member
Hi friends,

I would like to put a countdown timer in the hud of my maze project. Countdown from 60 or maybe 100. Then to warp to whatever the screen properties says when the timer ends. What would be the best way to go about doing that?

EDIT:

Updated with working code thanks to Dale!

put in HandleGameTimer script::

Code:
;;; handle game timer
    LDA gameTimerTicks
    CLC
    ADC #$01 ;how fast to run
    STA gameTimerTicks
    BCC +normalwhatever
                        ;;Joe's create monster script we're canceling out
                         ;;#$80, #$80, #$10 #$00
                        ;;x, y, what object, what state     
    SubtractValue #$02, myTimer, #$1, #$00 
        ;;arg0 = how places value has
        ;;arg1 - home variable
        ;;arg2 = amount to subtract
        ;;arg3 = what place value is receiving subtaction
    UpdateHudElement #$05
+normalwhatever
    
    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo
    LDA gameTimerHi
    ADC #$00
    STA gameTimerH

;; checking the value of the timer:
    LDA myTimer_10
    BNE +notEnded
    LDA myTimer
    BNE +notEnded
        ;; now 00
        ;; what we do:
        ;; execute a WARP !!!
        WarpToScreen warpToMap, warpToScreen, #$01
    +notEnded:

and put this in your Post Screen Load:

Code:
  ;; initialize the Timer to 60
  LDA #$0
  STA myTimer
  LDA #$6
  STA myTimer_10

and modify to your game! (look below for Dale's explanation)
 
Last edited:

dale_coop

Moderator
Staff member
This topic is a good start for that:
It was meant for nesmaker 4.1.5, but the general idea is in it. using a my timer hud variable, decreasing it...
 

dale_coop

Moderator
Staff member
Could you share your current Handle Game Timer script? I will check quickly how it can be modified in order to do what you want.
 

dale_coop

Moderator
Staff member
I need your script. Not the one from the topic (remember that topic was for the 4.1.5... that is really different than the current version. I guess you are using the recent 4.5.9 one, correct?). I need your file, in order to make modification for your file, your project ;)
 

5kids2feed

Well-known member
Ah, I see. Well my Handle Gamer Time file is blank because I have no idea what to do 🤷‍♂️ Atleast that's how the maze module sets it up? I'm pretty much a beginner when it comes to scripting. All I know how to do is setup up the user variable myTimer.. set it to 60 (because that's what I want).. annnnd that's about it lol.
 

5kids2feed

Well-known member
Ok.. updating here because we have the timer labeled as 4.5.9. in this post.

@dale_coop .. I've got something in HandleGameTimer.. i think we're in the right direction.. @Arctic Blizzard brought it to my attention that Joe was messing around with the game timer in the Advance Arcade Platform tutorial.. So I borrowed the code and added what should work for myTimer user variable that I set up.. but.. it's not working.. (it does work if i put it on a tile.. and the create an object works if i uncomment it) for some reason subtract and add values are not.. whats your input on this?

Code:
;;; handle game timer
    LDA gameTimerTicks
    CLC
    ADC #$01 ;how fast to run
    STA gameTimerTicks
    BCC +normalwhatever
                        ;;Joe's create monster script we're canceling out
                         ;;#$80, #$80, #$10 #$00
                        ;;x, y, what object, what state     
    SubtractValue #$02, myTimer, #$1, #$00 
        ;;arg0 = how places value has
        ;;arg1 - home variable
        ;;arg2 = amount to subtract
        ;;arg3 = what place value is receiving subtaction
    UpdateHudElement #$05
+normalwhatever
    
    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo
    LDA gameTimerHi
    ADC #$00
    STA gameTimerHi

@CutterCross if you're not busy too, would you mind taking a look?

Thanks everybody! We love you!
 

dale_coop

Moderator
Staff member
That script is correct.

Assign it to your "Handle Game Object" element (in the "Project Settings > Script Settings").

And create two user variables "myTimer" and "myTimer_10"... because your timer will use two digits.
2020-12-09-15-59-51-Project-Settings.png

(in that screenshot I set its initial value to 60... myTimer_10 = "6" and myTimer = "0")

And display your "myTimer" on your HUD as a number in the "Element 5" (because your timer script uses that hud element):
2020-12-09-15-58-43-NES-MAKER-4-5-9-Version-0x176-Twelve-Days-NESmas-MST.png


Now, you should have a count down timer on your screen
 

dale_coop

Moderator
Staff member
Now you will have to deal with the count time... what to do when it reaches ZERO.

The could should be added in that "handle game timer" script, anywhere... but I will suggest, just after the "UpdateHudElement #$05" line...

Code:
;; checking the value of the timer:
    LDA myTimer_10
    BNE +notEnded
    LDA myTimer
    BNE +notEnded
        ;; now 00
        ;; what we do:
        ;; execute a WARP !!!
        WarpToScreen warpToMap, warpToScreen, #$01
    +notEnded:



Also, you need to reset the Timer to "60" when the screen loads.
If you have a "Post screen load" script assigned (in your "Project Settings > Script Settings"), you could add the code in that script (else create a new script and assign to it), with hat code:
Code:
  ;; initialize the Timer to 60
  LDA #$0
  STA myTimer
  LDA #$6
  STA myTimer_10
 

5kids2feed

Well-known member
Dale! I Love you! Okay I got everything in.. but it's not counting down the timer.. It set it to 60, element 5 with max value 2 and no errors.. but for some reason will not countdown like in my last post to you:

but.. it's not working.. (it does work if i put it on a tile.. and the create an object works if i uncomment it) for some reason subtract and add values are not..

The script works if I put it in a tile (but for some reason will not work if I put it in my doHandleGameTimer..):

SubtractValue #$02, myTimer, #$1, #$00
;;arg0 = how places value has
;;arg1 - home variable
;;arg2 = amount to subtract
;;arg3 = what place value is receiving subtaction
UpdateHudElement #$05

I even tried to replace it with DEC myTimer... and still nothing.. frustrating@! o_O

I could cheat and add a monster that everytime it's timer ended subtract a value from myTimer but I don't want to take up any monster slots.
 
Last edited:

dale_coop

Moderator
Staff member
Have you assign the count down timer to the "handle Game timer"element in Project Settings > Script Settings ?

Also, when testing... just wait... the timer is very slow ! ;)
if too slow you can increase the "ADC #$01" ("ADC #$04" for example)...


2020-12-09-17-37-26-Project-Settings.png
 

5kids2feed

Well-known member
OMGGGGGG you did it!!!! I'm so dumb!! I was working with 2 doHandleGameTimer scripts and forgot to update to the other one... it's always the little things that get you!!! I'm so excited!!! DALE IS MY SAVIOR!!!!!

2 questions:

1. What about screens where I don't want the timer to be on? If I click don't show HUD will that work or do I need a script for certain rooms (main game)?

2. The value of my timer is running but at the beginning of the screen the values for my lives and my score disappear until i get hit or pickup a prize. Is there a way to get them showing again from the start?

@Arctic Blizzard come check it out. We got it workin!
 
Last edited:

dale_coop

Moderator
Staff member
If you don't want the timer, you will have to disable the code when the flag (any flag) is set for those screen.
If, for example, you want to use the "hide HUD"... then, you will have to add that code:
Code:
    LDA ScreenFlags00
    AND #%01000000         ;; if "hide hud" is set.
    BNE +normalwhatever    ;; skip all the code related to myTimer

Just before the "SubtractValue" line in your game timer script.
 

5kids2feed

Well-known member
If you don't want the timer, you will have to disable the code when the flag (any flag) is set for those screen.
If, for example, you want to use the "hide HUD"... then, you will have to add that code:
Code:
    LDA ScreenFlags00
    AND #%01000000         ;; if "hide hud" is set.
    BNE +normalwhatever    ;; skip all the code related to myTimer

Just before the "SubtractValue" line in your game timer script.

How are you so smart, Dale? Seriously.

EDIT: Nevermind about my second question.. everything was fixed the second time I ran my game lol. This timer is the main focus of my new game i'm working on. You just made my day.
 
Last edited:

kevin81

Active member
Looks like a solid way to implement a timer function! From a curious point of view, can someone explain to me what this code snippet actually does?

Code:
    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo
    LDA gameTimerHi
    ADC #$00
    STA gameTimerHi

It seems like it's adding zero to the variable, essentially changing nothing. Am I missing some hidden ASM functionality here? Something to do with the carrier maybe?
 

Jonny

Well-known member
Looks like a solid way to implement a timer function! From a curious point of view, can someone explain to me what this code snippet actually does?

Code:
    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo
    LDA gameTimerHi
    ADC #$00
    STA gameTimerHi

It seems like it's adding zero to the variable, essentially changing nothing. Am I missing some hidden ASM functionality here? Something to do with the carrier maybe?
Could be to offset it or something?
Try it without and see if it still works.
" If in doubt, comment it out "
 

Arctic Blizzard

New member
Hi friends,

I would like to put a countdown timer in the hud of my maze project. Countdown from 60 or maybe 100. Then to warp to whatever the screen properties says when the timer ends. What would be the best way to go about doing that?

EDIT:

Updated with working code thanks to Dale!

put in HandleGameTimer script::

Code:
;;; handle game timer
    LDA gameTimerTicks
    CLC
    ADC #$01 ;how fast to run
    STA gameTimerTicks
    BCC +normalwhatever
                        ;;Joe's create monster script we're canceling out
                         ;;#$80, #$80, #$10 #$00
                        ;;x, y, what object, what state    
    SubtractValue #$02, myTimer, #$1, #$00
        ;;arg0 = how places value has
        ;;arg1 - home variable
        ;;arg2 = amount to subtract
        ;;arg3 = what place value is receiving subtaction
    UpdateHudElement #$05
+normalwhatever
   
    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo
    LDA gameTimerHi
    ADC #$00
    STA gameTimerH

;; checking the value of the timer:
    LDA myTimer_10
    BNE +notEnded
    LDA myTimer
    BNE +notEnded
        ;; now 00
        ;; what we do:
        ;; execute a WARP !!!
        WarpToScreen warpToMap, warpToScreen, #$01
    +notEnded:

and put this in your Post Screen Load:

Code:
  ;; initialize the Timer to 60
  LDA #$0
  STA myTimer
  LDA #$6
  STA myTimer_10

and modify to your game! (look below for Dale's explanation)
Way cool. Sorry I haven't replied sooner. Was working on this timer all week. Then saw the updates and implemented them. But I wanted my timer to end and DEC myLives and put my player in action #07 hurt state for animation purposes. So it took two days of playing around with the code. But finally got it to do what I wanted it to do. Only problem is. The sfx I have that plays for all the other hurt actions doesn't play. But oh well. And timer resets before the level does. But I was just trying to get most of it done on my own. Since Dale_Coop helps so many of us. But thanks so much 5kids2feed & Dale_Coop. I'll post my version of the script in a bit. I'm at work right now.
Dale_Coop your the Best...
 

5kids2feed

Well-known member
No worries at all. I know.. I get lost in the code too. So I completely understand. Can’t wait to see what you came up with for the timer!

Yeah, Dale gets bombarded daily with questions and I think I’m like 80% of them hahah. He’s the best!
 
Top Bottom