[4.5.9] Create Conditional Text Conditions With TEXT_FREE

Bucket Mouse

Active member
Wouldn't it be nice to have NPCs tell you different things depending on what's happening in your game? The untouched NESMaker does not allow for this. The good news is, I've managed to pull conditional text off. The bad news is, this trick is not for newbies -- it requires mastery of several OTHER tricks I've already posted here.

The first requirement is knowledge of how to make a Multitile, which was the first trick I ever posted on these forums -- it saves precious custom tile space by using the same tile to perform tasks unique to each screen. You do this by taking advantage of the variable that holds the number of your current screen, which is called "camScreen."

Code:
LDA camScreen
CMP #$15
BNE +
((( custom stuff goes here )))
+

CMP #$17
BNE +
((( different custom stuff )))
+

Get the idea? It's easy to learn.

Next you need to know how to use TEXT_FREE to store text in multiple banks, which in turn requires activating userScreenBytes. When you've explored both those topics, come back here for the next step.

MAKE A "FAKE" NPC

Since you can't make an NPC say conditional dialogue in the native engine -- or at least not without overhauling a lot of it -- we'll have to make it a different way. The first step is to NOT check the "NPC" box for this particular sprite. In fact we won't check any box at all, nor will we give the NPC a bounding box. Doing either of those things causes the below trick to not work properly.

Stick your NPC on the screen wherever you want. On the square where you put it, make that tile solid. Then put the Multitile around all the places where the player might stand to talk to it. That's our fake version of what would normally happen, but it allows for a lot more customization.

Use this script in the Multitile:

Code:
LDA camScreen
CMP # ;put the number of your screen here
BEQ +
JMP +end
+
LDA npcTrigger
ORA #%00000001
STA npcTrigger
  
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
++
RTS

If you're confused right now, that's because you skipped a step! Otherwise you would recognize the DrawBox2 macro from my TEXT_FREE tutorial. That's what you get for rushing!

DrawBox2 pulls the userScreenByte0 number for that screen, checks the database you built in Bank 1A, and retrieves that specific text entry. You can pull any text entry from that bank at any time. You are not limited to four per screen!

HOW TO ADD CONDITIONAL DIALOGUE

Let's say you have an NPC that is meant to say one thing, but then say something else under specific conditions. Now, you can sort of pull this off natively by using the screen triggers and putting the same NPC on both versions of the screen. But you can do a lot more with this method.

Know how some NPCs will say something different if you talk to them twice? Here's how to make that happen here:

Code:
LDA camScreen
CMP # ;put the number of your screen here
BEQ +
JMP +end
+
LDA npcTrigger
ORA #%00000001
STA npcTrigger

LDA variable
BEQ + ; branches if equal to zero

;if variable is equal to 1:
INC userScreenByte0
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
DEC userScreenByte0
RTS
+
;if variable is equal to 0:
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
INC variable ; sets variable to 1 so this text is only read once
++
RTS

By adding and subtracting from userScreenByte0, we can pull up any text entry from Bank 1A that we want. It's no longer necessary that they be part of a group. And with variables, we can trigger events and have the NPC react to them an unlimited number of times. One NPC can potentially say seven different things depending on where the game's story is. The example below will say three separate things depending on what number a variable is set to.

Code:
LDA camScreen
CMP # ;put the number of your screen here
BEQ +
JMP +end
+
LDA npcTrigger
ORA #%00000001
STA npcTrigger

LDA variable
CMP #$01
BEQ +textone ; branches if equal to one
CMP #$02
BEQ +texttwo
CMP #$03
BEQ +textthree
JMP ++

textone:
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
RTS

texttwo:
INC userScreenByte0
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
DEC userScreenByte0
RTS

textthree:
textone:
INC userScreenByte0
INC userScreenByte0
DrawBox2 #BOX_1_ORIGIN_X, #BOX_1_ORIGIN_Y, #BOX_1_WIDTH, #BOX_1_HEIGHT, #TEXT_FREE
DEC userScreenByte0
DEC userScreenByte0
RTS
++

One important thing to remember: Having userScreenByte0 set to a number greater than zero will affect every NPC on that specific screen. You can't have one NPC using this method standing right next to another that doesn't use it. You'll get gibberish if you talk to the unaltered one, most likely.

How do you solve it? It helps to have more than one Multitile. On the second one, add the number to userScreenByte0 that will pull up the text entry for that NPC. Adjust as needed -- if the NPC has to say something three entries ahead, add 3 to userScreenByte0. Just remember to subtract it back at the end!
 
Last edited:
Top Bottom