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

java.lang.ArrayIndexOutOfBoundsException

Started by blombler, 31 July 2017 - 07:32 PM
blombler #1
Posted 31 July 2017 - 09:32 PM
Hello there,

After month now i'm still on that puzzle
https://pastebin.com/LJHwkQBZ
If you see i trying to get the energy status from the energy core of draconic evolution and
split it into diffrend parts of numbers to sick a > , < between…. that works pretty good.
But i want to bring it into a loop so it never stops and on screen it should't stop with a command like > sleep() <
But it says again and again this —> https://prnt.sc/g2ovd2 <—-
And me and my friend tryed everything out we know.

Thanks to the awnsers

Sorry for my bad english
Bomb Bloke #2
Posted 01 August 2017 - 01:48 AM
Every time you call a function, a new "instance" of that function goes on the end of the "function stack" (really a Java array with LuaJ, as is used by ComputerCraft). Every time a function completes, it's removed from the stack and execution continues from the point where the previous function instance left off.

You're shell.run()ing your own script file. Because none of these function instances ever return, but rather just keep adding new instances to the top of the stack, eventually this infinite loop causes you run out of the memory allocated towards such shenanigans and the resulting error is thrown.

Try wrapping the code you wish to repeat in a "while true do" block instead.

http://lua-users.org/wiki/ControlStructureTutorial
The Crazy Phoenix #3
Posted 01 August 2017 - 02:32 AM
Although Bomb Bloke's "while true do" solution is the best, there are a few unmentioned details about the call stack.
Namely, if the called function's output is returned in the current function (i.e. "return func()"), the called function will replace the current function in the stack instead of being added to it.