Hi all. I'm having a bit of a problem getting my text to type the right words correctly.
It works for the FIRST sentence, then it stops working after that.
When it prints out the text, it does something like this:
This is a test.
is a test.
is a test.
Etc..
You can't compile the code so I will attach an EXE to this post
Here is the code:
Backdrop On : Color Backdrop 0
Sync On
Start X
Type tTeletype
Text$
TextLen
Value$
XPos
YPos
Delay
Time
Char
Show
WordCount
CalcH
CalcSpaceW
NL$
EndType
Global TeleType As tTeleType
Make Object Cube 1, 10
Position Object 1, 0, 0, -10
Position Camera 0, 0, 10
Point Camera 0, 0, 0
w = 260
wnd = X Make Widget Window(w, 110)
X Set Widget Text wnd, "Help"
X Widget Maximize Box Off wnd
X Widget Minimize Box Off wnd
X Widget Resize Off wnd
l = X Make Widget Label(wnd, 10, 10, w-10, 20)
X Set Widget Text l, "Press SPACE to show the teletype text."
l = X Make Widget Label(wnd, 10, 30, w-10, 20)
X Set Widget Text l, "Press ENTER to hide it."
l = X Make Widget Label(wnd, 10, 50, w-10, 20)
X Set Widget Text l, "Press any key to close this window."
gosub setup_specialwords
add_special_word("is")
Do
If SpaceKey() Then SetTeleType( "This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10)+"This is a test!"+chr$(13)+chr$(10), screen width()/2, screen height()/2, 250 )
If ReturnKey() Then TeleType.Show = 0
If Scancode() and wnd<>0
X Transmit wnd, 1, 0, 0 `1=X_EV_CLOSE
wnd = 0
EndIf
X Prep Draw 2D
X Begin Drawing Text
X Set Text Color 2D 0xFFFFFFFF
X Draw Text "FPS: " + Str$(X Get Frame Rate()), 10, 10, 250, 30
DisplayTeleType()
X Finish Drawing Text
XRotate Object 1, WrapValue( Object Angle X( 1 ) + X Get Tween() )
ZRotate Object 1, WrapValue( Object Angle Z( 1 ) + X Get Tween() )
Update X
Sync
Loop
Function DisplayTeleType()
`Only show the teletype if set to 'on'
If TeleType.Show = 0 Then ExitFunction
`If the time is greater than the timeout then...
If hitimer() >= ( TeleType.Time + TeleType.Delay )
`Reset the timeout variable
TeleType.Time = hitimer()
`If the number of letters to be displayed is less than the total number of letters, show another letter.
If TeleType.Char < TeleType.TextLen
TeleType.Char = TeleType.Char + 1
TeleType.Value$ = Left$(TeleType.Text$, TeleType.Char)
__build_word_array(TeleType.Value$)
TeleType.WordCount = array count(g_temp_wordArray(0))
EndIf
EndIf
`Display the text string.
__display_text(TeleType.XPos, TeleType.YPos, 250, TeleType.Value$, 0xFFFFFFFF, rgb(68,207,0))
EndFunction
Function SetTeleType( Text$, X, Y, Delay )
`Set all the variables.
TeleType.Text$ = Text$
TeleType.TextLen = Len(Text$)
TeleType.Value$ = ""
TeleType.Delay = Delay
TeleType.Time = hitimer()
TeleType.XPos = X
TeleType.YPos = Y
TeleType.Char = 0
TeleType.Show = 1
TeleType.WordCount = 0
X Calculate Text Dimensions "^y"
TeleType.CalcH = X Get Text Height() + 2 ` maximum text height + margin of 2 pixels
X Calculate Text Dimensions "/"
TeleType.CalcSpaceW = X Get Text Width()
TeleType.NL$ = Chr$(13)
EndFunction
` You *MUST* gosub setup_specialwords BEFORE using any of the functions below
setup_specialwords:
global dim g_specialWords(0) as string
global dim g_temp_wordArray(0) as string
return
` Add a special word
function add_special_word(value$)
array insert at bottom g_specialWords()
g_specialWords(0) = lower$(value$)
endfunction
` Display some text, word wrapped, with special coloring
function __display_text(x_pos, y_pos, x_size, value$, normalColor, specialColor)
x_size = x_size + x_pos
cnt = TeleType.WordCount
cur_x = x_pos
cur_y = y_pos
h = TeleType.CalcH
space_w = TeleType.CalcSpaceW
for i=0 to cnt
t$ = g_temp_wordArray(i)
if t$ = TeleType.NL$ ` newline
cur_x = x_pos
cur_y = cur_y + h
else
X Calculate Text Dimensions t$
w = X Get Text Width()
if cur_x + w > x_size
cur_y = cur_y + h
cur_x = x_pos
endif
if __is_special_word(t$)
X Set Text Color 2D specialColor
else
X Set Text Color 2D normalColor
endif
X Draw Text t$, cur_x, cur_y, cur_x+w, cur_y+h
cur_x = cur_x + w + space_w
endif
next i
endfunction
` INTERNAL FUNCTION, DO NOT USE
function __build_word_array(value$)
l = len(value$)
base$ = ""
empty array g_temp_wordArray(0)
for i=1 to l
c$ = mid$(value$, i)
if c$=" "
array insert at bottom g_temp_wordArray()
g_temp_wordArray() = base$
base$ = free string$()
else
if c$=chr$(13)
array insert at bottom g_temp_wordArray()
g_temp_wordArray() = base$
array insert at bottom g_temp_wordArray()
g_temp_wordArray() = chr$(13)
base$ = free string$()
else
base$ = base$ + c$
endif
endif
next i
if len(base$) > 0 and base$<>" "
array insert at bottom g_temp_wordArray()
g_temp_wordArray() = base$
endif
base$ = free string$()
endfunction
` INTERNAL FUNCTION, DO NOT USE
function __is_special_word(value$)
cnt = array count(g_specialWords())
v$ = lower$(value$)
for i=0 to cnt
if v$ = g_specialWords(i) then exitfunction 1
next i
endfunction 0
CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!