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

VM Error: Array index out of bounds

Started by Dave-ee Jones, 05 October 2017 - 04:30 AM
Dave-ee Jones #1
Posted 05 October 2017 - 06:30 AM
Hoi!

Yes, I know we've seen this error before.
Yes, I know this is probably going to be super obvious and I'm probably going to realise it as soon as I post this.

But anyway, the line is line 90 where it says:

n_ARG_START = _LINE:find("[")

n_ARG_START is called earlier to make it local (it's inside an if statement).
_LINE looks like this:

_LINE = "<color['blue']>"
which is passed to the function the if statement is under, so it's local as well. For some reason it thinks it's out of index even though there is clearly a '[' there, and it's not an array..

I've tested to make sure it is actually that line by putting print functions before and after it, and yes it is that line.

Any ideas? I'm happy to post more code if needed, but there shouldn't be anything else affecting it.
Edited on 05 October 2017 - 04:31 AM
SquidDev #2
Posted 05 October 2017 - 07:48 AM
Use this instead:

n_ARG_START = _LINE:find("[", 1, true)

string.find allows the use of Lua patterns for more complex matches. However, your pattern is considered malformed as "[" is a special character - thus the error. Passing true as the third argument means it will not be interpreted as a pattern and so everything works as expected.
Dave-ee Jones #3
Posted 05 October 2017 - 11:12 PM
Doh! I should have known that because I'd escaped every single other one in the program! I just forgot that one and didn't realise!

Thanks! I'll do

n_ARG_START = _LINE:find("%[")