LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to easily make TEXT that Appears Letter By Letter?

Root / Programming Questions / [.]

ElzoBroCreated:
I thought this would be useful to make text games look a little bit nicer! The only way i can think of is by making each letter in a sentence one by one like LOCATE 1,1:PRINT"H" WAIT 30 LOCATE 2,1:PRINT"E" WAIT 30 LOCATE 3,1:PRINT"L" WAIT 30 LOCATE 4,1:PRINT"L" WAIT 30 LOCATE 5,1:PRINT"O" WAIT 30 LOCATE 6,1:PRINT"!" See how much space and time that takes up? Please, and Thank You!

I'd rather do this:
TEXT$="HELLO!"
FOR A%=1 TO LEN(TEXT$)
 CLS
 PRINT LEFT$(TEXT$,A%)
 WAIT 30
NEXT A%
EDIT: not to bash your idea though, I used to do the same lol

I seriously need to study/practice with DATA myself for once.But i think I sort of of get it. A% is the set of letters being placed now and LEFT$ tells it what to leave out, then Next A% is what set of letters it will show next, Right? (Probably Not!)

I don't like data ;( I love it?

Uhhh this doesn't use DATA at all. A% is just the integer value (basically just A if you don't use OPTION STRICT) that is the main part of the for loop. Basically, the for loop makes A% increase by one at the NEXT A%, and the LEFT$ tells what to include. So for the first time around, A% is equal to 1, so the LEFT$ takes the first character to the left of the string and prints it. Then, A% is equal to 2, and the LEFT$ this time takes the first two characters and prints them, eventually printing every character in the string. tldr lol

Haha sorry but it reminds me of data so much

Explain with comments (I hope to make it less complicated for beginners lol)
TEXT$="HELLO!" 'setting what will be printed
FOR A%=1 TO LEN(TEXT$) 'the beginning of the loop. A% will start at 1 and end at the length of the text. At the NEXT A%, at returns to here and makes A% greater by one. Once A% equals the length of the text, it breaks from the loop, continuing along. 
 CLS 'clears screen duh
 PRINT LEFT$(TEXT$,A%) 'prints however many characters on the left of the text. example: if A%=2 then just the first two characters of the text
 WAIT 30 'waits so it doesnt all come at the same time
NEXT A% 'tells the for loop to restart and increment A% by whatever STEP value you put (if omitted then its just 1)
hope this works lol EDIT: apparently theres no text wrap for code so youll have to scroll left and right

Cool, oh also found out how to have multiple lines and have a specific line a different color =)

joleable, the code you posted won't let you do anything else until the text is completed. I have a code for this if you have a game loop but I will post it later.

I hope this would work
TEXT$="HELLO!"  'This is what will be printed
CLS 'Does just like DOS Does.
FOR T%=1 TO LEN(TEXT$) 'This sets the T% for use later in the loop. It basically sets the loop to start at 1 and stop at the length of TEXT$
 PRINT MID$(TEXT$, A%, 1); 'Prints one character of the TEXT$ variable
 WAIT 30 'Waits so that you can actually see what it is printing
NEXT T% 'Tells the loop to increment T% and go back to the FOR statement

If you want just one character, you can treat a string as an array, like so:
A$ = "Hello!"
FOR I% = 0 TO LEN(A$)-1 'pretty sure it's 0-based
   PRINT A$[I%]; 'include ; to prevent newline
   IF A$[I%] != " " THEN VSYNV 10 'wait only on non-space characters
NEXT

joleable, the code you posted won't let you do anything else until the text is completed. I have a code for this if you have a game loop but I will post it later.
Insert this line into your code then
IF BUTTON(0) AND 16 THEN BREAK

A general formula for a sequence of events that happen regularly, that doesn't block other events:
' When the sequence starts
SEQUENCE%=TRUE
NEXTEVENT%=MAINCNT+delay between events
Regularly:
IF (SEQUENCE% AND (MAINCNT>=NEXTEVENT%)) THEN DO_EVENT
Procedure:
DEF DO_EVENT
' Do event
' If not the last event in sequence, INC NEXTEVENT%,delay between events
' If the last event in sequence, SEQUENCE%=FALSE
RETURN

Well thanks for all the help guys! Looks like I still have quite a bit to learn, but i'm determined to learn more.