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

Please help - Can't get my program to work

Started by Alexh173, 07 August 2012 - 01:48 PM
Alexh173 #1
Posted 07 August 2012 - 03:48 PM
Hello, I am pretty new to LUA and have been getting errors with this program that i have written :/


mon=peripheral.wrap("right")
mon.setCursorPos(8,2)
mon.write("Reactor Status")
mon.setCursorPos(1,4)
mon.write("--------------------------------------------")
mon.setCursorPos(2,6)
Reactor = rs.testBundledInput("back",colors.red)
if Reactor == false then
mon.write("Reactor Status : OFF")
end
if Reactor == true then
mon.write("Reactor Status : ON")
end
Power = rs.getInput("top")
if Power == false then
mon.clear()
mon.setCursorPos(8,6)
mon.write("Shutting Down")
sleep(2)
os.reboot()
end

I am getting the error:

shell:17: vm error: bios:38: vm error:
java.lang.ArrayIndexOutOfBoundsExeption

In case you Can't tell I have the red wire (from bundled cable) connected to a reactor so it show's the status of it on a monitor

And the part marked Power is so when my control computer gets shutdown, this computer reboots.

Oh and one more thing - I have been trying to find ways to get this program always stay active, for eg. automatically reload itself when the reactor status changes (because i have to manually reset the computer to see on the screen, also Be able to turn of the computer without having to shutdown the main one and then reset this computer :/

Any help appreciated!
wilcomega #2
Posted 07 August 2012 - 04:10 PM
from what i can see i think this is a bug in computercraft because the error massage has to do something with Java and a computer uses Lua so maybe you want to wait for a Lua Expert before you report the bug in the bugs section
ardera #3
Posted 07 August 2012 - 05:52 PM
If it prints really this message: "shell:17: vm error: bios:38: vm error: java.lang.ArrayIndexOutOfBoundsExeption"
then its an error by something like this

function a()
a()
end

shell:18 is a function call…
bios:38 is another function call…

im not sure and I don't want to say something wrong, but it can be that one function called another function, and that 256 times…

If Im right, then its not a big problem. Only reboot the computer and run the program again. If the exception is thrown another time,
then you can post this problem in "bugs"

but this error message is very mysterious… ;)/>/>
KFAFSP #4
Posted 07 August 2012 - 06:15 PM
I think this is a kind of StackOverflow error. Maybe he used the wrap to often or the monitor was out of sync. Recusrion is helpful, but tricky sometimes ;)/>/>.
KaoS #5
Posted 08 August 2012 - 08:14 AM
are you sure that is your entire code?
Alexh173 #6
Posted 08 August 2012 - 09:10 AM
kao, No it isnt, but this was the one the error seemed to come from.

the rest of code is:

Startup program:

shell.run("Starting")

Starting:

os.pullEvent()
if redstone.getInput("top") == true then
mon=peripheral.wrap("right")
mon.setCursorPos(6,6)
mon.write("Terminal Booting")
sleep(3)
shell.run("reactor")
end

Reactor:

mon=peripheral.wrap("right")
mon.setCursorPos(8,2)
mon.write("Reactor Status")
mon.setCursorPos(1,4)
mon.write("--------------------------------------------")
mon.setCursorPos(2,6)
Reactor = rs.getBundledInput("back",colors.red)
if Reactor == true then
mon.write("Reactor Status : ON")
end
if Reactor == false then
mon.write("Reactor Status : OFF")
end
Power = rs.getInput("top")
if Power == false then
mon.clear()
mon.setCursorPos(8,6)
mon.write("Shutting Down")
sleep(2)
os.reboot()
end
sleep(3)
shell.run("reactorrel")

reactorrel:


mon.clear()
term.clear()
sleep(1)
shell.run("reactor")

The Reactorrel program is there so the program reactor restarts itself until the computer gets switched off by the control computer.
Luanub #7
Posted 08 August 2012 - 10:38 AM
Yeah you will want to change some things. Its a combination of a couple different issues.

1- You're nesting your programs within each other. While this works its not ideal by any means. I suggest you do like I did in this post and convert the multiple programs into functions within a single program.
http://www.computerc...ct-my-programs/

2- You're using global variables with the same name in the different programs. its always best to use local vars so that they don't conflict with each other.
Instead of:

mon=peripheral.wrap("right")

do:

local mon=peripheral.wrap("right")

Fixing those two things should hopefully clear up some of your issues.

Another thing I would personally do is in the Reactor code change:

Reactor = rs.getBundledInput("back",colors.red)
to:

Reactor = rs.testBundledInput("back", colors.red)

It's always been less error prone in my personal experience.


EDIT: I did also notice that instead of running a loop to keep the reactor you are doing a shell.run("reactor"). When you update the code change that to a while loop. This is probably whats causing the Java error.
Example:

while true do
local reactor = rs.testBundledInput("back", colors.red)
if reactor then
-- do stuff for reactor being on
else
-- do stuff for it being off
end
end
Edited on 08 August 2012 - 08:43 AM
Shadow1 #8
Posted 08 August 2012 - 10:58 AM
This is fixed, Close threat.
Alexh173 #9
Posted 08 August 2012 - 02:33 PM
Thanks luanub, Although i still have a problem. I am not getting: too long without yielding :/
Lyqyd #10
Posted 08 August 2012 - 03:44 PM
Stick a sleep(0) somewhere in the loop.
Alexh173 #11
Posted 08 August 2012 - 04:23 PM
Thanks, all seems to be fine now ;)/>/>