Please Help With Textbox

Hello!

So in my game, I have the "B" button mapped to "a_create_projectile.asm", which looks like this:

Code:
 LDA gameHandler
    AND #%00100000
    BEQ notNPCstate_proj
 JMP doneShooting
 notNPCstate_proj
 LDA weaponsUnlocked
 AND #%00000010
 BNE canShoot
 JMP doneShooting
canShoot:
LDX player1_object
 GetCurrentActionType player1_object


 CMP #$03
 BNE notAlreadyShooting
 JMP doneShooting 
notAlreadyShooting
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 ChangeObjectState #$03, #$02
 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
 
    LDA Object_movement,x
    AND #%00000111
    STA temp2
    TAY ;; now y contains direction, so we can figure out position offset
    
     LDA Object_x_hi,x
     ;;; offset x for creation
     CLC
     ADC weaponOffsetTableX,y
     SEC
     SBC xScroll
     SEC 
     SBC #$08 ;; width of gun 
     STA temp
     LDA Object_y_hi,x
     CLC
     ADC weaponOffsetTableY,y
     sec
     sbc #$08 ;; height of gun
     STA temp1

 
    CreateObject temp, temp1, #OBJ_PLAYER_PROJECTILE, #$00, currentNametable
  
    ;;;; 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
     PlaySound #SND_SHOOT
doneShooting:

RTS


;;000 down
;010 right
;100 up
;110 left

However, I would also like the "B" button to activate a textbox. What does the code need to look like in order for that to happen?
 

dale_coop

Moderator
Staff member
Do you have a melee script assigned to a button? Sometimes, the melee script also contains the activation text code?
If you have a Melee script assigned and if it doesn't activate your text boxes... It's great, it means you can add a new script "b_activate_text_box.asm" to your input scripts and assign it to your "B" button, too (you can assign multiple scripts to a same button).

For that, I would suggest this "b_activate_text_box.asm" script (create a new script file in your "Routines\Basic\InputScripts" folder):
Code:
    LDA textboxHandler  ;; check if the text is already displayed
    AND #%11000000 
    BEQ +
    RTS
    +

    LDA textboxHandler
    AND #%00010000 ;; if the b button is pressed
                    ;; but the box + text have been activated
                    ;; and also the 'do box' bit is OFF
                    ;; that means this is ready to "go away".
                    
    BEQ checkToTurnTheTextboxOn ;; hasn't started yet
    
    ;; begin turning the textbox off.
    LDA gameHandler
    ORA #%00100000
    STA gameHandler
    ;;; are we turning this on or off?
    ;;; check for more
    ;;; check for 'choice'.
  
    LDA #$00
    STA updateNT_offset
    STA updateNT_H_offset
    STA updateNT_V_offset
    
    LDA #%10001000
    STA textboxHandler
    RTS
   
checkToTurnTheTextboxOn:  
   LDA npc_collision
    BEQ noNPCcollision
    LDA textboxHandler
    AND #%10000000
    BNE noNPCcollision
   LDA gameHandler
    ORA #%00100000
    STA gameHandler
    ;;; are we turning this on or off?
    ;;; check for more
    ;;; check for 'choice'.

turnTheTextboxOn:
  
    LDA #%10000000
    STA textboxHandler
    
noNPCcollision:
    RTS

Add that "b_activate_text_box.asm" script, in your "Input scripts" (under "Scripts" in the left side tree view of your NESmaker main window).
And assign it to your "B" button, in the "Input Editor".
 
dale_coop said:
Do you have a melee script assigned to a button? Sometimes, the melee script also contains the activation text code?
If you have a Melee script assigned and if it doesn't activate your text boxes... It's great, it means you can add a new script "b_activate_text_box.asm" to your input scripts and assign it to your "B" button, too (you can assign multiple scripts to a same button).

For that, I would suggest this "b_activate_text_box.asm" script (create a new script file in your "Routines\Basic\InputScripts" folder):
Code:
    LDA textboxHandler  ;; check if the text is already displayed
    AND #%11000000 
    BEQ +
    RTS
    +

    LDA textboxHandler
    AND #%00010000 ;; if the b button is pressed
                    ;; but the box + text have been activated
                    ;; and also the 'do box' bit is OFF
                    ;; that means this is ready to "go away".
                    
    BEQ checkToTurnTheTextboxOn ;; hasn't started yet
    
    ;; begin turning the textbox off.
    LDA gameHandler
    ORA #%00100000
    STA gameHandler
    ;;; are we turning this on or off?
    ;;; check for more
    ;;; check for 'choice'.
  
    LDA #$00
    STA updateNT_offset
    STA updateNT_H_offset
    STA updateNT_V_offset
    
    LDA #%10001000
    STA textboxHandler
    RTS
   
checkToTurnTheTextboxOn:  
   LDA npc_collision
    BEQ noNPCcollision
    LDA textboxHandler
    AND #%10000000
    BNE noNPCcollision
   LDA gameHandler
    ORA #%00100000
    STA gameHandler
    ;;; are we turning this on or off?
    ;;; check for more
    ;;; check for 'choice'.

turnTheTextboxOn:
  
    LDA #%10000000
    STA textboxHandler
    
noNPCcollision:
    RTS

Add that "b_activate_text_box.asm" script, in your "Input scripts" (under "Scripts" in the left side tree view of your NESmaker main window).
And assign it to your "B" button, in the "Input Editor".

I've sadly already tried this, I get the following error:
"C:\Users\hello\Documents\NESmaker_4_1_5\GameEngineData>asm6 MainASM.nes game.nes demo.txt
pass 1..
Routines\Basic\ModuleScripts\InputScripts\b_activate_text_box.asm(32): Label already defined.
Routines\Basic\ModuleScripts\InputScripts\b_activate_text_box.asm(45): Label already defined.
Routines\Basic\ModuleScripts\InputScripts\b_activate_text_box.asm(50): Label already defined."
 

dale_coop

Moderator
Staff member
So, it means you have ALREADY that code in your input scripts.
Do you have a melee script? could you share it?
 
Top Bottom