Jump to content




Custom line split troubles, CC bug?


  • You cannot reply to this topic
3 replies to this topic

#1 CometWolf

  • Members
  • 1,283 posts

Posted 11 January 2014 - 07:39 AM

Running this piece of code on the online lua demo http://www.lua.org/cgi-bin/demo
local tLines = {}
local lineLength = (51)
local message = "This is the first line|second line|This line is longer than the 51 character limit, and will be split!"
while #message > 0 do
  local line = message:sub(1,lineLength)
  local newLine = line:find"|" --check for new line character
  if newLine then
	line = line:sub(1,newLine-1)
	message = message:sub(#line+2,#message)
  elseif #line == lineLength then
	local endSpace = line:find"%s%S-$" or lineLength
	line = line:sub(1,endSpace)
	message = message:sub(#line+1,#message)
  else
	message = ""
  end
  table.insert(tLines,line)
end
for i=1,#tLines do
  print(tLines[i])
end

As expected splits the string into lines at all "|" and at the space closest to the length limit, and prints the following:

Quote

This is the first line
second line
This line is longer than the 51 character limit,
and will be split!

However, running it on a computercraft computer prints the following

Quote

This is the first line
second line| This line is longer th
n the 51 character limit, and will be split!
And im just left thinking... wtf is going on here?

Edited by CometWolf, 11 January 2014 - 07:54 AM.


#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 11 January 2014 - 09:21 AM

There is a bug when using string.find on a string that was created using string.sub.

#3 CometWolf

  • Members
  • 1,283 posts

Posted 11 January 2014 - 09:37 AM

Ah i see, thanks for the info.

#4 Anavrins

  • Members
  • 775 posts

Posted 11 January 2014 - 10:39 AM

https://twitter.com/...888477389574144
This bug should be fixed in the next update.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users