-snip-
First of all, THANKS! But… Have you tried executing the code? I am getting vm exception negative array size :/ its on that line
line = line..string.rep(" ",endSpace-lineLength) --fill in the blank spaces with well... spaces
Shouldn't it be
lineLenght-endSpace ? I added your code, fixed that line with
if endSpace-lineLenght>0 then … end but it's weirdly adding the spaces (in fact, it's not adding them till the eol, only about 1 space is added). On the other hand, the output from (I added this to a wrap(str,limit) function) wrap("this is some text asdasdasdasd",5) is something like
this
me
xt
sdasd
...
(simply cutting off first 2 symbols if line!=1)… Weird isn't it? I'm using CC 1.63, it might be because of that, I debugged your code at first with my Android device and SigmaScript while at school, and it worked (well, dunno if the spaces were added properly, SigmaScript doesn't offer better output than a console-no colors, etc.). by the way here is your code when put into a function that should work
Spoiler
--this doesn't work, as it doesn't fill in the missing spaces, can't figure out why after 2 hours of programming without a break :D/> '
function wrap(str, limit)
local tLine = {}
while #str > 0 do --splits text into a table containing each line
--print(#str) debug
local line = str:sub(1,limit)
local newLine = string.find(line.."","\n") --check for new line character
if newLine then
line = line:sub(1,newLine-1)
str = str:sub(#line+2,#str)
elseif #line == limit then
local endSpace = line:find"%s$" or line:find"%s%S-$" or limit
line = line:sub(1,endSpace)
if endSpace-limit>0 then
line = line..string.rep(" ",endSpace-limit) end --fill in the blank spaces with well... spaces
str = str:sub(#line+1,#str)
else
str = ""
end
tLine[#tLine+1] = line
end
local out=""
for i,v in ipairs(tLine) do --put the for loop into the draw function and instead of writing newline
out=out.."\n"..tostring(v) --set new cursor position with term.setCursorPos(x,y+i) (and of course, here return tLine)
end
return out
end
that last comment is for a modified version that actually wrap the text on screen, here:
...
--end of that function is changed
return tLine
end
--and later used in my code to wrap text on-screen as follows:
if string.len(this.text)>this.width then
term.setCursorPos(x,y)
local space=this.width*this.height --this is not used now, will be as soon as I finally figure out the damned text wrapping!!!
for i,v in ipairs(wrap(this.text,this.width)) do
term.setCursorPos(x,y+i)
term.write(tostring(v))
end
else
term.setCursorPos(x,y)
term.write(wrap(this.text))
end
Hope I'm not too stupid and it's not obvious…. (but as usual, it is isn't it? Im just sooo tired… )
And hope that you will be able to help me, thanks for any feedback! :)/>