writing text, letter by letter

Blitz3D Forums/Blitz3D Beginners Area/writing text, letter by letter

Atomic Duck(Posted 2004) [#1]
Is it possible to "copy" a letter from a string (with a sentence) to another string (an empty one)

The effect I want to achieve, is that of the Shining Force games.

Can I use REPLACE or something else?


Rob Farley(Posted 2004) [#2]
a$="Hello there"

for n=1 to len(a)
print mid(a,n,1)
next


(tu) sinu(Posted 2004) [#3]
also you could work out each string in advance before displaying it to see if it fits the line, and if not draw it to the next line.


Atomic Duck(Posted 2004) [#4]
Rob, thanks for your effort,... but this will only display text in a "vertical way",
and I would like the text to be displayed in a horizontal way

Anyway, this is what I've come up with:
Graphics 640,480,0,1
w_line$=("GREETINGS ADVENTURER, WHAT WOULD YOU LIKE TO DO ?")	
textlength=Len(w_line$)+1	
p=1
Repeat
	If MilliSecs() > wait + 100 Then 
		wait=MilliSecs()
		setchar$ = Mid$(w_line$,p,1)
 		Locate q,10 
		Write setchar$
 		p=p+1
 		q=q+8
	EndIf
Until p>textlength  



I admit it's a bit crude, and it only works with the standard blitz font at the moment.

And Sinu's idea is very good! :D
I'll put that one in, too

Thanks


Rob Farley(Posted 2004) [#5]
Have you seen the text command?


Atomic Duck(Posted 2004) [#6]
Thanks Rob,
it's less hassle, heh?

Graphics 640,480,0,1
w_line$=("GREETINGS ADVENTURER, WHAT WOULD YOU LIKE TO DO ?")	
textlength=Len(w_line$)+1	
p=1
Repeat
	If MilliSecs() > wait + 100 Then 
		wait=MilliSecs()
		setchar$ = Mid$(w_line$,p,1)
 		text q,10,setchar$ 
 		p=p+1
 		q=q+8
	EndIf
Until p>textlength  


thanks


Rob Farley(Posted 2004) [#7]
An alternative so you don't have exact spacing would be...

Graphics 640,480,0,1
w_line$=("GREETINGS ADVENTURER, WHAT WOULD YOU LIKE TO DO ?")	
textlength=Len(w_line$)+1	
p=1
Repeat
	If MilliSecs() > wait + 100 Then 
		wait=MilliSecs()
 		text 0,10,left$(w_line$,p) 
 		p=p+1
	EndIf
Until p>textlength



Atomic Duck(Posted 2004) [#8]
Wow Rob,

the code is getting smaller by the minute :D :D
thank you for your input(it works like a charm)


Rob Farley(Posted 2004) [#9]
Well... If you want small...

w_line$="GREETINGS ADVENTURER, WHAT WOULD YOU LIKE TO DO ?"
for n=1 to len(w_line)
text 0,10,left(w_line,n)
delay 100
next



Atomic Duck(Posted 2004) [#10]
Repeat
    print "I am not worthy"
Forever


;)


Rob Farley(Posted 2004) [#11]
Or indeed if you want to be clever...

This is a tidy way of doing it so you don't need to create loads of loops, just create a function to pass the x,y and text into it, then just use type_text instead of text.

Graphics 640,480
type_text(0,10,"GREETINGS ADVENTURER, WHAT WOULD YOU LIKE TO DO ?" )
Type_text(50,100,"Anything?")
type_text(0,200,"This is a much better way of doing it!")
End

Function type_text(x,y,t$)
For n=1 To Len(t)
Text x,y,Left(t,n)
Delay 100
Next
End Function



Nobody(Posted 2004) Edit [#12]
Yes you're right. That's even better.

FYI,

[rant]

The function-part always gave me headaches.
I've used (and learned) DIV now for about 3 years.
DIV uses processes instead of functions.

Both programs work differently, although there are
quite a few similarities.

I've Blitz now for about 2 months, and I've to "unlearn" some of DIV's habits. (like the repeat..until)

[/rant]

Rob Farley(Posted 2004) [#13]
repeat..until is really handy, as is while...wend. You've just got to use the right loop for the right job.

If you know the exact beginning and end of a loop a for..next is probably the way to go.