Posted 07 May 2013 - 06:31 AM
Hi! I'm trying to make a game.
I got this error:
paintutils:3: vm error:
java.lang.ArrayIndexOutOfBoundsException: 256
My lua code:
Oh, I'm also using CC-emu
Whats wrong?
I got this error:
paintutils:3: vm error:
java.lang.ArrayIndexOutOfBoundsException: 256
My lua code:
Spoiler
-- Variables --
debug = "Debug"
w, h = term.getSize()
-- Values --
limeName = "Lime gem: "
limeSell = 10
lblueName = "Light blue gem: "
lblueSell = 15
yellowName = "Yellow gem: "
yellowSell = 50
orangeName = "Orange gem: "
orangeSell = 100
-- Stats --
money = 0
playerName = "nil"
limeGems = 0
lblueGems = 0
yellowGems = 0
orangeGems = 0
-- End Stats --
-- End Variables --
-- Game --
function playGame()
-- Variables --
slc = 1
minX = 13
maxX = w-1
minY = 2
maxY = h-1
maxGem = 20
spawnedGems = 0
newX = math.random(minX, maxX)
newY = math.random(minY, maxY)
local function frame()
term.setBackgroundColor(colors.black)
term.clear()
paintutils.drawLine(12, 1, 12, h, colors.red)
paintutils.drawLine(12, 1, w, 1, colors.red)
paintutils.drawLine(12, h, w, h, colors.red)
paintutils.drawLine(w, 1, w, h, colors.red)
paintutils.drawLine(1, 1, 1, h, colors.red)
paintutils.drawLine(1, 1, 1, h, colors.red)
paintutils.drawLine(2, 1, 2, h, colors.red)
paintutils.drawLine(3, 1, 3, h, colors.red)
paintutils.drawLine(4, 1, 4, h, colors.red)
paintutils.drawLine(5, 1, 5, h, colors.red)
paintutils.drawLine(6, 1, 6, h, colors.red)
paintutils.drawLine(7, 1, 7, h, colors.red)
paintutils.drawLine(8, 1, 8, h, colors.red)
paintutils.drawLine(9, 1, 9, h, colors.red)
paintutils.drawLine(10, 1, 10, h, colors.red)
paintutils.drawLine(11, 1, 11, h, colors.red)
term.setBackgroundColor(colors.lime)
term.setTextColor(colors.black)
term.setCursorPos(5, h-4)
print(" Exit ")
end
function spawnGem()
if spawnedGems >= maxGem then
playGame()
else
paintutils.drawPixel(newX, newY, color)
spawnedGems = spawnedGems + 1
gem()
end
end
function gem()
while true do
newX = math.random(minX, maxX)
newY = math.random(minY, maxY)
colorNum = math.random(1,4)
if colorNum == 1 then
color = colors.orange
spawnGem()
elseif colorNum == 2 then
color = colors.yellow
spawnGem()
elseif colorNum == 3 then
color = colors.lime
spawnGem()
elseif colorNum == 4 then
color = colors.lightBlue
spawnGem()
end
end
end
frame()
gem()
end
function frame2()
slc = 0
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(math.floor(w-string.len("Logged in as: "..playerName))/2, 2)
print("Logged in as: "..playerName )
paintutils.drawPixel(1, 4, 32)
paintutils.drawPixel(1, 6, 8)
paintutils.drawPixel(1, 8, 16)
paintutils.drawPixel(1, 10, 2)
term.setBackgroundColor(1)
term.setCursorPos(3, 4)
print(limeName ..limeGems)
term.setCursorPos(3, 6)
print(lblueName ..lblueGems)
term.setCursorPos(3, 8)
print(yellowName ..yellowGems)
term.setCursorPos(3, 10)
print(orangeName ..orangeGems)
term.setBackgroundColor(32)
term.setCursorPos(10, 15)
print("Play")
term.setCursorPos(20, 15)
print("Sell Gems")
end
function game()
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(math.floor(w-string.len("Name: "))/2, 2)
write("Name: ")
playerName = read()
if playerName == "" then
game()
else
frame2()
end
end
-- End Functions --
game()
-- User Interaction --
while true do
event, key, x, y = os.pullEvent()
if event == "mouse_click" then
if slc == 0 then
if x >= 10 and x <= 18 and y == 15 and key == 1 then
playGame()
elseif x >= 20 and x <= 30 and y == 15 and key == 1 then
sellGems()
elseif slc == 1 then
if x >= 5 and x <= 10 and y == h-4 and key == 1 then
slc = 0
frame2()
end
end
end
end
end
Oh, I'm also using CC-emu
Whats wrong?