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

ArrayIndexOutOfBoundsException: 256

Started by adwhitenc, 04 July 2012 - 12:41 AM
adwhitenc #1
Posted 04 July 2012 - 02:41 AM
I have the following code:


local mon = peripheral.wrap("top")
local oil = 0
local coke = 0
function redstoneEvent(p1, p2)
if(rs.testBundledInput("right", colors.lightGray)) == true then
coke = coke + 1
end
if(rs.testBundledInput("right", colors.green)) == true then
oil = oil + 1
end
end
repeat
mon.clear()
mon.setCursorPos(1,1)
mon.write("Oil gained:")
mon.write(oil)
mon.setCursorPos(1,2)
mon.write("Coke gained: ")
mon.write(coke)
local event, p1, p2 = os.pullEvent()
if event == "redstone" then
redstoneEvent(p1, p2)
end
until event == "char" and p1 == "x"
mon.clear()
os.shutdown

and receive the following error:

shell:17: vm error: bios:38 vm error:
java.lang.ArrayIndexOutOfBoundsException: 256

any idea why. I'm new to lua but not to programming, any help will be appreciated
MysticT #2
Posted 04 July 2012 - 02:50 AM
Is that the code you used? Cause you shouldn't be able to run it.
Some errors:

local mon = peripheral.wrap("top")
local oil = 0
local coke = 0
function redstoneEvent(p1, p2)
  if(rs.testBundledInput("right", colors.lightGray)) == true then
    coke = coke + 1
  end
  if(rs.testBundledInput("right", colors.green)) == true then
    oil = oil + 1
  end
end
repeat
  mon.clear()
  mon.setCursorPos(1,1)
  mon.write("Oil gained:")
  mon.write(oil) -- not sure if you can use numbers here
  mon.setCursorPos(1,2)
  mon.write("Coke gained: ")
  mon.write(coke) -- same as above
  local event, p1, p2 = os.pullEvent()
  if event == "redstone" then
    redstoneEvent(p1, p2)
  end
until event == "char" and p1 == "x"
mon.clear()
os.shutdown -- missing brackets ()

That error is normally caused by a recursive function that overflows the stack, but there's none here. So, if you can, open the program file (located in .minecraft/saves/<YourWorld>/computer/<Computer ID>) and copy-paste the program here.
adwhitenc #3
Posted 04 July 2012 - 02:54 AM
Yeah, i figured that it was those variables. No idea how to fix it, but ill keep poking around…

Edit: so I tried changing the code to:

mon.write("Oil gained:"..oil)
mon.setCursorPos(1,2)
mon.write("Coke gained: "..coke)
Due to the code on this
and nothing changed, I got the exact same error…
MysticT #4
Posted 04 July 2012 - 03:02 AM
Yeah, i figured that it was those variables. No idea how to fix it, but ill keep poking around…
Errr… That's not what I said, those variables are fine. There's no way they can cause that error.
Most likely you left something out in the code you posted.
adwhitenc #5
Posted 04 July 2012 - 03:12 AM
Problem solved, case closed, for whatever reason, my startup script was calling itself instead of the program, thank you for your hel and sorry for wasting your time…