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

parallel:22: bios:-1: vm error: java.lang.ArrayIndexOutOfBoundsException

Started by thedriver87, 24 June 2013 - 04:49 PM
thedriver87 #1
Posted 24 June 2013 - 06:49 PM
its all in the title. that error results from the following code


local trigger=false
if not trigger then
	print("holding for redstone signal")
end
while not trigger do
	 event=rs.getInput("bottom")
	if event==true then
		 trigger=true
	end
end

when I apply a redstone signal to the bottom. otherwise the code runs waiting for the input fine.

*edit* after some further testing the problem was using a disk as the source of the code and removing the disk before triggering. the rest of the program wasnt there to be refferenced i guess
VADemon #2
Posted 24 June 2013 - 07:19 PM
Mother of servers… you run the while-loop nonstop… CPU won't love you after that :(/>

But really, what you need is a real CC event that handles redstone changes: os.pullEvent("redstone")
local trigger=false
if trigger==false then --easier to understand
	print("holding for redstone signal")
end

while not trigger do -- repeat until rs signal from bottom is ACTIVE
	local event = os.pullEvent("redstone")
	--the code below will be executed as soon as redstone signal is changed
	if rs.getInput("bottom")==true then
		trigger = true
		print("Active redstone signal on bottom!")
	else
		print("One of the sides other than bottom got activated by a redstone signal")
	end
end
That should work. Basically it waits for a redstone signal to change ("redstone" event) and then it checks whether it is the bottom side that is activated by redstone
theoriginalbit #3
Posted 25 June 2013 - 12:52 AM
Mother of servers… you run the while-loop nonstop… CPU won't love you after that :(/>
Not the case at all. The program would be killed by ComputerCraft if it runs any more than ~10 seconds because it is taking from the runtime of other computers.