button sequences and "double tapping". Where to begin?

WillElm

New member
I know there's a thread on this, but it has no info and it's archived. NESMaker has been around longer now, so does anyone know how to do this? You know, double tap left to dash, or do fighting game style moves?

For double tapping, I think the logic might look like this: Assign the input script to a left button press. Was left pressed a second time within the time limit? If not, skip to end of script. If left was pressed within the limit, do double tap stuff.

I'm guessing I need to start really looking into timers. I learned that you can set timers for when you do a changeobjectstate with the second value, but i don't think it would make sense to start there.
 

WillElm

New member
So I'm brainstorming ways to do this. I can't test anything until tomorrow, but I'm wondering how far off base I am with this idea. I don't know if it's possible to branch backwards for one, and I'm also wondering about my logic.

The basic idea is that a left button press sets a timer into motion. That timer counts up to 5, then stop and store the variable (chosen arbitrarily for now). Another left button press will check to see if the timer is below 5. If it is, your character will do a thing. If it's not, they won't.

I guess the big hole in the logic is that it's a double tap- I'm wondering if the variable check at the beginning of doubletap.asm will be moot, since a left button press sets it to 0 anyway. But, maybe it would work for a sequence that isn't 2 of the same presses? O perhaps it matter what sequence i put the script in (put doubletap.asm first)? or, i guess i could assign doubletap.asm to hold left?

I might get a chance to mess with this later, but I'll probably have to wait until tomorrow night. I figured, why not write down my ideas- if I get somewhere it might be valuable.


timer.asm
Code:
;;MAPPED TO A LEFT BUTTON PRESS;;
;;I want this to act as a timer that will change a variable. 
;;That variable will be checked by a LEFT button press that will make the player dash. Essentially a double tap.

    
LDA #$00
STA tapTimer     ;;set the timer variable to 0 

timerCode:

    LDA tapTimer       ;;  should initially be 0, but increase frame by frame until the limit is reached
;   CLC        ;;not sure if needed
    ADC #$01       ;; add 1 to the variable
    STA tapTimer       ;; store the new value
    CMP #$05          ;;  has it reached the frame limit?
    BCC timerCode     ;; if not, loop back
 ;;If the limit is reached, store the variable
    STA tapTimer
    RTS

doubletap.asm
Code:
;;MAPPED TO A LEFT BUTTON PRESS;;

LDA tapTimer
CMP #$05 ;;has the frame limit been reached?
BEQ noDoubleTap  ;;if so, don't do double tap stuff

;; if not, run the double tap code

dashCode:

;;;DASH/DOUBLE TAP CODE HERE;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;

noDoubleTap:
rts
 

MistSonata

Moderator
So, I can tell you right now that this code won't work because if timer.asm goes off every time you press left, it will always return that the tapTimer has reached the frame limit, even if you only press left once. What you want to do instead is to create tapTimer as a user variable in your Project Settings and set the initial value to 0. Then find your HandleGameTimer.asm script (Look in Project Settings>Script Settings) and underneath the line that says "DO WHATEVER READS OF THE GAMETIMER YOU MIGHT WANT HERE." write this code:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;; 
	;; DO WHATEVER READS OF THE GAMETIMER YOU MIGHT WANT HERE.
	LDA tapTimer
	BEQ skipTapTimer ;; if tapTimer is already zero, it doesn't need to be decreased
	DEC tapTimer
	
	skipTapTimer:

This will make it so that it will decrease tapTimer by 1 every frame until it hits zero. Then, you make a "press left" script that will check tapTimer, and make your character dash if it returns a non-zero value. Something like this:

Code:
;;; PRESS LEFT SCRIPT

	LDA tapTimer
	BNE dashLeft ;; if tapTimer is zero, that means a double press hasn't correctly occured
	;; therefore continue at normal speed and set tapTimer 
	LDA #30 ;; setting tapTimer to 30 means that you will have 30 frames (roughly half of a second) to press left again
	STA tapTimer
		;; === HERE YOU WOULD SET YOUR SPEED TO WHATEVER IS YOUR NORMAL, NON-DASHING SPEED
	JMP continueLeftMovementCode 	
		
	dashLeft: ;; if tapTimer is NOT zero, it means that a double press has correctly occured
		;; === HERE YOU WOULD SET YOUR SPEED TO WHATEVER IS YOUR DESIRED DASHING SPEED
	
	continueLeftMovementCode:
	;; Continue your movement code as normal here.

Some notes on the timing, "HandleGameTimer.asm" will execute once every frame, and the game runs at roughtly 60 frames per second. I set it to #30 (not #$30, that's a hex number and it's not the same as 30) so that it gives you half a second between when you press the left button the first time, to when you press the left button a second time to activate the dash.

I hope this helps.
 

WillElm

New member
thank you! it looks like a good place to begin. i figured that my 2 scripts would interfere with each other. This week is busier than I expected, but if I get this working in a way that's transferrable to other projects, I'll write it up as a tutorial.
 
Top Bottom