This is a function that will wrap text (if it goes past a certain point it will go to a new line). It's very simple to use, just call the textWrap function:
textWrap(x,y,size x, size y, text$, text color)
There are another two functions that the textWrap function calls, but you dont need them.
Use the mouse to watch the text wrapping in action.
sync on : sync rate 60
set display mode 1024,768,32
`Main Loop
do
sx=mousex()-100
sy=mousey()-100
ink rgb(92,92,92),0 : box 100,100,100+sx,100+sy
textWrap(100,100,sx,sy,"Hello, my name is Zotoaster. Use this function for text wrapping",rgb(255,255,255))
sync
cls
loop
`Functions - Label
function textWrap(x,y,sx,sy,text$,col as dword)
ink col,0
for t=1 to getTokens(text$," ")
posx=posx+text width(getToken(text$," ",t-1))
if (posx+text width(getToken(text$," ",t)))>sx
posx=0
posy=posy+text height(getToken(text$," ",t))
endif
text x+posx,y+posy,getToken(text$," ",t)
next t
endfunction
`Functions - String
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
ret$=token$+sp$
endfunction ret$
[edit]
The subject is supposed to say "Text", not "Test". Lol