This function will split up and print a long string so that it fits within a box of a given width. It uses 3 helper functions, but they could be merged in if you feel like it.
This
function is recursive, meaning that it will call itself. It can also be somewhat slow, so if anyone has a faster method, feel free to post it.
In order to make the small speed problem less noticable, the function
calls itself before printing, meaning that it will work out all the logic first, and then
print all the lines in reverse from the bottom up, very quickly.
Usage:
printMulti(string$, x, y, width, spacing)
string$ is the string you wish to print
x is the x position of the lines
y is the y position of the first line
width is the width of the box to fit the text in
spacing is the vertical spacing between lines
function findSpace(string$)
i = len(string$)
while (mid$(string$, i) <> " ")
dec i
endwhile
endfunction i
function getLastWord(string$)
i = findSpace(string$)
word$ = right$(string$, len(string$)-i)
string$ = left$(string$, i-1)
endfunction word$
function getRemainingString(string$)
i = findSpace(string$)
string$ = left$(string$, i-1)
endfunction string$
function printMulti(string$, x, y, width, spacing)
if (string$ = "") then exitfunction
new$ = ""
while (text width(string$) > width)
new$ = " " + getLastWord(string$) + new$
string$ = getRemainingString(string$)
endwhile
new$ = right$(new$, len(new$)-1)
printMulti(new$, x, y+spacing, width, spacing)
text x, y, string$
endfunction
Enjoy
-Jeff
Space Game WIP