Two Button Inputs 4.5.9

baardbi

Well-known member
Sometimes you might want to have a two button input to perform an action, like for example holding UP and pressing the B-button to shoot a special weapon. This tutorial will show you how to do it. In this example we will be using UP + B to shoot the special weapon.

1. Our input script for shooting the special weapon needs a check for one of the inputs. I'm going to choose the B-button in this case.

;;;;;;; Special weapon input script ;;;;;;;;;;;;;;;;;

; NESMaker Gamepad / Controller bits
; %10000000 - Right
; %01000000 - Left
; %00100000 - Down
; %00010000 - Up
; %00001000 - Start
; %00000100 - Select
; %00000010 - B
; %00000001 - A

;;; Check if the B-button is pressed
LDA gamepad
AND #%00000010 ;B-button
BNE +
RTS ;;; If the B-button is not pressed we exit the script.
+


;;; Limit player projectiles to 1
CountObjects #%00000100
CMP #1
BCC +canShootSpecial
RTS
+canShootSpecial:

TXA
PHA
TYA
PHA
LDX player1_object
LDA Object_x_hi,x
CLC
ADC #$04
STA tempA
LDA Object_screen,x
ADC #$00
STA tempD
LDA Object_y_hi,x
CLC
ADC #$04
STA tempB
LDA Object_direction,x
AND #%00000111
STA tempC
CreateObjectOnScreen tempA, tempB, #2, #$00, tempD ;;; Game object 2 is the special weapon
;;; x, y, object, starting action.
;;; and now with that object, copy the player's
;;; direction and start it moving that way.
LDA tempC
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp1
TXA
STA temp
StartMoving temp, temp1
PLA
TAY
PLA
TAX

+skipShootSpecial:

RTS

2. Choose the other input button you want to use. In this case I will choose UP. We will set this one up in the Input Editor with Hold. Choose your special input script.

hold.PNG

3. You're done. However, if you have another input set for the B-button, both projectiles will be shot. In that case you need a check in the other input script. Make sure that (in this case) UP is not being pressed.

;;;;;;;; Normal projectile input script ;;;;;;;;;;;;

; NESMaker Gamepad / Controller bits
; %10000000 - Right
; %01000000 - Left
; %00100000 - Down
; %00010000 - Up
; %00001000 - Start
; %00000100 - Select
; %00000010 - B
; %00000001 - A

;;; Check if UP is pressed on the D-pad
LDA gamepad
AND #%00010000 ;;; UP
BEQ +
RTS ;;; If UP is being pressed we exit the script.
+


;;; Limit player projectiles to 1
CountObjects #%00000100
CMP #1
BCC +canShootNormal
RTS
+canShootNormal:

TXA
PHA
TYA
PHA
LDX player1_object
LDA Object_x_hi,x
CLC
ADC #$04
STA tempA
LDA Object_screen,x
ADC #$00
STA tempD
LDA Object_y_hi,x
CLC
ADC #$04
STA tempB
LDA Object_direction,x
AND #%00000111
STA tempC
CreateObjectOnScreen tempA, tempB, #1, #$00, tempD ;;; Game object 1 is the normal weapon
;;; x, y, object, starting action.
;;; and now with that object, copy the player's
;;; direction and start it moving that way.
LDA tempC
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp1
TXA
STA temp
StartMoving temp, temp1
PLA
TAY
PLA
TAX

+skipShootSpecial:

RTS
 

NightMusic

Member
Sometimes you might want to have a two button input to perform an action, like for example holding UP and pressing the B-button to shoot a special weapon. This tutorial will show you how to do it. In this example we will be using UP + B to shoot the special weapon.

1. Our input script for shooting the special weapon needs a check for one of the inputs. I'm going to choose the B-button in this case.



2. Choose the other input button you want to use. In this case I will choose UP. We will set this one up in the Input Editor with Hold. Choose your special input script.

View attachment 7734

3. You're done. However, if you have another input set for the B-button, both projectiles will be shot. In that case you need a check in the other input script. Make sure that (in this case) UP is not being pressed.
Apologies, my understanding was that you can just set Up and B together in the inputs to trigger the script. Does the direction and button press together not work in Nesmaker. Again apologies for my misunderstanding of something I thought worked in the gui.
 

baardbi

Well-known member
Apologies, my understanding was that you can just set Up and B together in the inputs to trigger the script. Does the direction and button press together not work in Nesmaker. Again apologies for my misunderstanding of something I thought worked in the gui.
For some reason that doesn't seem to work so great. That's why I use the Hold thing together with a little piece of code in the input script. That seems to be the most consistent way of doing it (at least in my experience).
 

NightMusic

Member
For some reason that doesn't seem to work so great. That's why I use the Hold thing together with a little piece of code in the input script. That seems to be the most consistent way of doing it (at least in my experience).
totally. i just tried jump n some other stuff and they werent acting proper with the up etc... you're so intuitive, thanks man! and THANK YOU again :)
 

SHLIM

Active member
they wont act correctly because its looking for both inputs pressed at once! baards way makes sure that one button is selected before the other will trigger.
 
Top Bottom