This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
libraryaddict's profile picture

Java VM error. java.lang.outofboundsexception with code

Started by libraryaddict, 21 March 2012 - 09:58 AM
libraryaddict #1
Posted 21 March 2012 - 10:58 AM
function tag(msg)
  local returnTag = {}
  local one = 1
  repeat
	local firstletter = string.find(msg, "[", one)
	local lastletter = string.find(msg, "]", one)
	one = lastletter
	returnTag[#returnTag+1] = string.sub(msg, firstletter, lastletter)
	msg = string.sub(msg, lastletter+1, string.len(msg))
	until not string.find(msg, "[", one)
  return unpack(returnTag)
end

It complains about line 5 with the "["
Why is this happening?
And how can I fix it.
Advert #2
Posted 21 March 2012 - 11:04 AM
You need to escape the brackets with a % sign in Lua patterns.