Please review the following code:
FUNCTION input(text$)
temp$ = ""
rem take down the menu
for nr = 8000 to 8006
if object exist(nr) = 1 then delete object nr
next nr
rem fast 3d backdrop
make object plain 8999,640,480
LOCK OBJECT ON 8999
POSITION OBJECT 8999,0,0,400
SET OBJECT 8999,1,0,0,0,0,0,1
TEXTURE OBJECT 8999,8043
x = 10
y = 15
repeat
y = 15
repeat
length = len(text$)
wIndex = 0
for i = 1 to length
if mid$(text$,i) = " "
wIndex = i
endif
if text width(left$(text$,i)) > 600
exit
endif
next i
text x,y,left$(text$,wIndex-1)
y = y + text height(text$)
text$ = right$(text$,length-wIndex)
until text width(text$) < 600
text x,y,text$
if keystate(14) = 0 then number$ = inkey$() else number$ = "-1"
if val( number$ ) > -1 and val( number$ ) < 10 and delay < 1
temp$ = temp$ + number$
delay = 5
endif
if keystate(14) = 1 and delay < 1 : temp$ = left$(temp$, len(temp$)-1) : delay = 5 : endif
if delay > 0 then delay = delay - 1
text x,y + text height(text$),temp$
sync
until returnkey() = 1
answer = val( temp$ )
DELETE OBJECT 8999
ENDFUNCTION answer
I'm using a modified version of a text output code I found, and while it works with normal text it doesn't work in this modification. The screen is set to a width of 800. If I enter any string that's over one line (text width > 600), only the last line gets printed. I'm confused - why doesn't this work, and how can I fix it?

A mod has been erased by your signature because it was larger than 600x120