2 Buttons have to be pressed to activate Script

peteria

New member
how would i make it that both up and B have to be pressed to activate the script? right now it just registers it as either pressing up or b … thank you in advance!
 

Dirk

Member
Indeed.
I tried it with the following settings in the input editor: Hold B + Up.
This works for me.
 

peteria

New member
my goal would be that only when up and b both are pressed one projectile gets shot, not when pressing either b or up (which happens when i put it to PRESS)
 

dale_coop

Moderator
Staff member
Oh, so keep your script assign only to the shoot button (B)
And add a code, at the beginning of the script, that would check if the (UP) button si pressed.... if not, you skip the script.

Here the code:

Code:
    LDA gamepad
    AND #%00010000	;; if UP is pressed
    BNE +
    RTS			;; if not, stop the script
    +
 

peteria

New member
oh what wed do without you Dale, thank you so much for your help :D I wish you a good rest of your day and ill report back in a second ^^
 

peteria

New member
okay hmm … so here's how the script looks like:
Code:
        LDA gamepad
    AND #%00010000  ;; if UP is pressed
    BNE +
    RTS         ;; if not, stop the script


canShoot:
    LDX player1_object
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 3 lines: 
    ;;; check if already shooting (assuming the shoot action step is 05)
    ;GetCurrentActionType player1_object
    ;CMP #$05
    ;BNE notAlreadyShooting
    JMP checkIfCanShoot 
    
notAlreadyShooting:
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 1 line: 
    ;;; if not already shooting, change it's action step (assuming the shoot action step is 05)
    ;ChangeObjectState #$05, #$02
    
    ;;; if you want your player stops when he's shooting, comment out the following lines:
    ;LDA Object_movement,x
    ;AND #%00001111
    ;STA Object_movement,x
    ;LDA #$00
    ;STA Object_h_speed_hi,x
    ;STA Object_h_speed_lo,x
    ;STA Object_v_speed_hi,x
    ;STA Object_v_speed_lo,x
    
;; if was already shooting
checkIfCanShoot:
    ;; will check if the weapon is charged (if Ammo > 0) :
    LDA myAmmo
    BNE continueShooting    ;; if not equal to 0, we can shoot
    ;;if no Ammo, we're done here.
    RTS
    
;; if enought Ammo we can continue shooting:
continueShooting:
    LDA Object_movement,x
    AND #%00000111
    STA temp2
    TAY

    LDA Object_x_hi,x
    SEC 
    SBC #$08 ;; width of projectile 
    STA temp
    LDA Object_scroll,x
    SBC #$00
    STA temp3

    LDA temp
    ;;; offset x for creation
    CLC
    ADC projOffsetTableX,y
    STA temp
    LDA temp3
    ADC #$00
    STA temp3

    LDA Object_y_hi,x
    CLC
    ADC projOffsetTableY,y
    sec
    sbc #$08 ;; height of projectile
    STA temp1   


    CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp3

    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x

    ;; start Updating Ammo
    DEC myAmmo
    LDA myAmmo
    ;;; 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
    UpdateHud HUD_myAmmo
    ;; finished Updating Ammo

    ;PlaySound #SND_SHOOT
    
doneShooting:
    RTS
and here's the error I received:
Routines\Basic\ModuleScripts\InputScripts\b_create_projectile_usingAmmo.asm(3): Branch out of range.

I tried some variations but I cant seem to figure out what I did wrong … :eek:
 

Oonan

New member
On line 3 you have BNE + which is branch if not equal go to +. You don’t have a + in your script. The next + you have in your fully assembled code is out of range. Try changing to the + to canShoot or put the + after the RTS on line 4. Either way I think that should fix your problem.
 

dale_coop

Moderator
Staff member
As Oonan wrote you missed my "+" line.
I gave you 5 lines of code (it's a small code), you copied only 4 of them. >_<
Please guys, if you ask for help, and you have error... check again. You might have missed something ;)
 
Top Bottom