(Final)NitroText - RPG-Like Output Text from FAT/Nitro

Learn to use DS Game Maker by Example!

(Final)NitroText - RPG-Like Output Text from FAT/Nitro

Postby Foxi4 » February 15th, 2011, 5:01 pm

Ever wanted to add Output Text that appears on a "one letter after another" basis, just like in most commercial video games instead of outputting a big slab of text? Well, this simple tutorial is going to help you do exactly that.

After we start out project, let's declare two variables that'll be necessary for us. I declared them as "Global" since in my game, text appears really often.

Let's call them "frame" and "limit" and set them as Unsigned Byte - we'll need them later.

Next, let's create our text-controlling object. Let's call it "Textbox".
In the object, assign these STEP actions (so that they're activated every single frame):

Loop frame from 0 to 10 //this will loop our "frame" variable from 0 to 10.
Start Block
IF frame is equal to 10 //this will cause activating the code when the loop reaches its peak point.
Start Block
Set Variable limit to limit+1 //this will add 1 to the limt variable each time 10 frames pass in-game.
Execute Code PA_BoxText(1,1,1,32,18,"Insert your text here",limit);
End Block
Wait for VBL
End Block

...and that's it! Easy, wasn't it? The only thing that's "different" from the usual set of actions found in DSGM5 is the PaLib code. I'll give you the syntax for it and explain it.

PA_BoxText(screen,basex,basey,maxx,maxy,"text",limit)

Screen - the screen you want to output to. 1 for the top, 0 for the bottom.
BaseX - the X coordinate of the left side of the "text box" (in tiles, like all other coordinates in this function)
BaseY - the Y coordinate of the top of the "textbox"
MaxX - the X coordinate of the right side of the "textbox" ends.
MaxY - the Y coordinate of the bottom of the textbox
Text - Self-explainatory. Text must be wrapped in " ".
Limit - The limit of how many characters/digits can be displayed.

The trick in this example is that each 10 frames, the "limit" variable we inputed instead of a standard digit was rising by 1, thus, the ammount of letters outputted on the screen did the same. Simple, reliable, works.

I can send the source if anyone wants it, but I think the tutorial is clear enough. Ask if you want it :)

~Foxi4 out!

EDIT: Code is obselete, revised version HERE: http://dsgamemaker.com/dsgmforum/viewtopic.php?f=6&t=342&start=20#p7543

EDIT2: Code above also obselete, NitroText(Final) available here: viewtopic.php?f=6&t=342&start=60#p16756
Last edited by Foxi4 on November 14th, 2011, 1:21 am, edited 6 times in total.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1114
Joined: December 31st, 2010, 3:25 am

Re: RPG-Like Output Text

Postby biomechanic » February 15th, 2011, 10:10 pm

Thank you so much for this tutorial! Just the other day I was actually thinking about this dilemma and that there should be a pretty simple way of doing this. Gonna try it out right away for my projects! :)
biomechanic
 
Posts: 1
Joined: February 15th, 2011, 10:07 pm

Re: RPG-Like Output Text

Postby Foxi4 » February 18th, 2011, 1:12 pm

I'm glad that I could help you. There are a few things you need to remember though.

When you have a conversation between two characters, the "limit" variable has to be reseted to 0 before the other person starts to speak. Otherwise it will display the entire message as a huge slab of text, and you don't want that.

Another thing is that the "limit" variable is still rising +1 each 10 frames, even when there is no more text left to be displayed. You have to stop it somehow, either by wrapping it in an IF condition or just deleting the text controlling object entirely when the conversation has finished.

I didn't mention it since I thought it's kinda obvious when you read the code and understand the syntax. It's a matter of experimenting - stop the limit increase in whatever way you think works best for you.


Loop frame from 0 to 10 //this will loop our "frame" variable from 0 to 10.
Start Block
IF frame is equal to 10 //this will cause activating the code when the loop reaches its peak point.
Start Block
IF Variable limit less than (total ammount of characters that can fit in your text box)
Start Block
Set Variable limit to limit+1 //this will add 1 to the limt variable each time 10 frames pass in-game.
Execute Code PA_BoxText(1,1,1,32,18,"Insert your text here",limit);
End Block
End Block
Wait for VBL
End Block

This is a revised version of the code. The difference from the previous one is that limit is rising only if it hasn't yet reached a certain point, that point being the maximum ammount of characters in your text box. When that point is reached, the limit variable no longer increases and the text remains displayed.

I'm adding the source and a special, compiled .nds that will help anyone understand the concept behind frames and the Text Boxes.

http://foxi4.w.interii.pl/RPG%20Text%20Engine.dsgm
http://foxi4.w.interii.pl/RPG%20Text%20Engine.nds
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1114
Joined: December 31st, 2010, 3:25 am

Re: RPG-Like Output Text

Postby mudy247 » May 1st, 2011, 9:05 pm

This code works really good!

I have a question though. How do you make the next line go down 3 lines if you want it to? Like giving it more space in between the lines.


Like how I just skipped two spaces here.

I was thinking of stopping the first line and then repeating the code to do the second line 3 spaces down, but then it does both lines at the same time and I can't get the second line to go after the first.
mudy247
 
Posts: 17
Joined: April 30th, 2011, 5:09 pm

Re: RPG-Like Output Text

Postby ElderKain » May 1st, 2011, 9:21 pm

Also how to change the text color into something else could be helpful as well. That way it can match the a project's design better.
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Re: RPG-Like Output Text

Postby Foxi4 » May 1st, 2011, 9:52 pm

PA_SetTextCol (u8 screen, u16 r, u16 g, u16 b);

R G B ranges between 0 and 31, unlike the standard 0-255.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1114
Joined: December 31st, 2010, 3:25 am

Re: RPG-Like Output Text

Postby ElderKain » May 1st, 2011, 10:06 pm

Foxi4 wrote:PA_SetTextCol (u8 screen, u16 r, u16 g, u16 b);

R G B ranges between 0 and 31, unlike the standard 0-255.



ok.. and how do i implement that into the program? when i add that to an "Execute Code" object, it gives me this error when i try to run

C:\DSGMTempP2_IWantYouGone30561541>make
Build process start for project "DSGMTempP2_IWantYouGone30561541"...
.
main.c
In file included from c:/DSGMTempP2_IWantYouGone30561541/source/main.c:6:0:
c:/DSGMTempP2_IWantYouGone30561541/include/GameWorks.h: In function 'btnPlayTouc
hNewPress_Event':
c:/DSGMTempP2_IWantYouGone30561541/include/GameWorks.h:60:18: error: expected ex
pression before 'u8'
c:/DSGMTempP2_IWantYouGone30561541/include/GameWorks.h:60:18: error: too few arg
uments to function 'PA_SetTextCol'
c:/devkitPro/PAlib/include/nds/arm9/PA_Text.h:255:20: note: declared here
make[1]: *** [main.o] Error 1
make: *** [build] Error 2

C:\DSGMTempP2_IWantYouGone30561541>pause
Press any key to continue . . .


Then I get the compile error message.
I don't know jack when it comes to PAlib code installment.
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Re: RPG-Like Output Text

Postby Foxi4 » May 1st, 2011, 11:08 pm

Alright then, it's Code School time!

u8 - unsigned byte (8-bit)
Screen - 0 for bottom, 1 for top.
R, G, B - values between 0 and 31

so...

PA_SetTextCol (1, 10, 10, 10); <--- Very much like this.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1114
Joined: December 31st, 2010, 3:25 am

Re: RPG-Like Output Text

Postby mudy247 » May 1st, 2011, 11:19 pm

Do you know how to add more spaces Foxi4? Like in between the lines of text.
mudy247
 
Posts: 17
Joined: April 30th, 2011, 5:09 pm

Re: RPG-Like Output Text

Postby ElderKain » May 1st, 2011, 11:24 pm

how come the colors don't show up like they are suppose too?

If I use
PA_SetTextCol (0, 255, 175, 15);
I looks like a dull red in the tested output when on MSPaint those RGB values make an orange color.
But When I use
PA_SetTextCol (0, 255, 10, 10);
it comes out orange but on MSPaint it's a reddish color?

I might be because the RGB on MSPaint isn't set on a 256 color palate, but still it should go to closest value even if it's on 256.... and it's like following the opposite on the RGB value spectrum when testing out the DS app...

@mudy247:
I think you use \n to add extra lines.
because
\n = next line just do \n\n to add 1 space between the text lines, and \n\n\n to add 2 spaces between lines.
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Re: RPG-Like Output Text

Postby JanMulder » May 1st, 2011, 11:25 pm

Foxi4 wrote:R G B ranges between 0 and 31, unlike the standard 0-255.
here and yet not here
JanMulder
 
Posts: 726
Joined: December 30th, 2010, 3:08 pm

Re: RPG-Like Output Text

Postby James » May 1st, 2011, 11:30 pm

Divide your color components by 8 and round.
James
Site Admin
 
Posts: 810
Joined: December 30th, 2010, 3:23 am
Location: Lancaster University, England

Re: RPG-Like Output Text

Postby ElderKain » May 1st, 2011, 11:34 pm

Ah ok, thanks James ^.^

I'm using
PA_SetTextCol (0, 29, 20, 1);
for the orange now ^.^
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Re: RPG-Like Output Text

Postby Nobody » May 2nd, 2011, 12:00 am

James wrote:Divide your color components by 8 and round.


Thanks, i've been trying to figure out how the did the color conversion. Maybe now i can make a successful collision map system.
Feel free to ask me for help. I'm on the forum a lot.

Recent Projects:
Crafters DS (Minecraft 2D Clone!) viewtopic.php?f=13&t=3082 (latest project!)
The Living Dead - viewtopic.php?f=13&t=1582
Mario Craft - viewtopic.php?f=8&t=1736 (Most Popular!)
Spawn Zombies - viewtopic.php?f=13&t=3444 (Newest)
User avatar
Nobody
 
Posts: 1942
Joined: February 14th, 2011, 12:08 am
Location: United States of America

Re: RPG-Like Output Text

Postby mudy247 » May 2nd, 2011, 1:18 am

ElderKain wrote:@mudy247:
I think you use \n to add extra lines.
because
\n = next line just do \n\n to add 1 space between the text lines, and \n\n\n to add 2 spaces between lines.


When I tried that I either got an error
PA_BoxText(1,1,1,32,18,"Insert your text here" /n "second line of text",limit);
or it showed the /n
PA_BoxText(1,1,1,32,18,"Insert your /n text here",limit);
like 'Insert your /n text here'

I'm not exactly sure how to do it. I've very new :)
mudy247
 
Posts: 17
Joined: April 30th, 2011, 5:09 pm

Re: RPG-Like Output Text

Postby James » May 2nd, 2011, 1:49 am

Code: Select all
PA_BoxText(1,1,1,32,18,"Insert your /n text here",limit);

Yes, that's almost right. It should be a backwards slash.

\n
James
Site Admin
 
Posts: 810
Joined: December 30th, 2010, 3:23 am
Location: Lancaster University, England

Re: RPG-Like Output Text

Postby ElderKain » May 2nd, 2011, 2:24 am

I wish there was a variable to change the text typing speed?
Is there a way that can be done?
I know you can put the "Wait for VBL" block in the same block area as the Draw frame / Draw limit objects as in Foxi4's example project, but that goes too slow.



Also is there a way to call up another object from another object event?
like when i click a button object, it will start up what is inside another object.
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Re: RPG-Like Output Text

Postby mudy247 » May 2nd, 2011, 2:29 am

ElderKain wrote:I wish there was a variable to change the text typing speed?
Is there a way that can be done?
I know you can put the "Wait for VBL" block in the same block area as the Draw frame / Draw limit objects as in Foxi4's example project, but that goes too slow.



What I did was I put
Loop frame from 0 to 2
Start Block
IF frame is equal to 2
Start Block

instead of 10 which made it faster somehow. I was just messing with it.
mudy247
 
Posts: 17
Joined: April 30th, 2011, 5:09 pm

Re: RPG-Like Output Text

Postby mudy247 » May 2nd, 2011, 2:30 am

James wrote:
Code: Select all
PA_BoxText(1,1,1,32,18,"Insert your /n text here",limit);

Yes, that's almost right. It should be a backwards slash.

\n



Oh wow. I feel dumb for not seeing that lol :grin: Thanks!
mudy247
 
Posts: 17
Joined: April 30th, 2011, 5:09 pm

Re: RPG-Like Output Text

Postby ElderKain » May 2nd, 2011, 3:05 am

mudy247 wrote:
ElderKain wrote:I wish there was a variable to change the text typing speed?
Is there a way that can be done?
I know you can put the "Wait for VBL" block in the same block area as the Draw frame / Draw limit objects as in Foxi4's example project, but that goes too slow.



What I did was I put
Loop frame from 0 to 2
Start Block
IF frame is equal to 2
Start Block

instead of 10 which made it faster somehow. I was just messing with it.


Hmmm when I modify that, it doesn't change the speed at all....
oh well, I can work around it.
That, and stylus tapping buttons, don't work all the time when it's on the same screen as the typing text....
So for this to work, i'm gonna have to change the screen locations on my project, lol.

I sure wish I knew how to call another object from an another object interaction...
ElderKain's DeviantArtDSGM v5.12 Project List/DLs (Under Construction) ●
/人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\ /人 ◕ ‿‿ ◕ 人\
ElderKain
 
Posts: 56
Joined: April 11th, 2011, 3:11 am
Location: USA Iowa

Next

Return to Tutorials & Examples

Who is online

Users browsing this forum: No registered users and 3 guests

cron