Posted 11 October 2013 - 12:31 AM
I am making an os and I got this error
" java.lang.ArrayIndexOutOfBoundsException"
I got this error working on window()
Here is my code
Thank You!
" java.lang.ArrayIndexOutOfBoundsException"
I got this error working on window()
Here is my code
local backgroundColor = colors.lime
buttons = {}
startMenuItems = {
"Restart:reboot",
"Shutdown:shutdown",
"Run:*"
}
local startMenuIsOpen = false
local windowIsOpen = false
function drawDesktop()
window(1,1,1,1,"text","text")
term.setBackgroundColor(backgroundColor)
term.clear()
term.setCursorPos(1,19)
term.setBackgroundColor(colors.blue)
term.clearLine()
addButton(1,19,7,1,colors.cyan,colors.white,"[START]","start")
windowIsOpen = false
startMenuIsOpen = false
end
function addButton(xPos,yPos,xSize,ySize,buttonColor,textColor,text,name)
buttons[name] = {xPos=xPos,yPos=yPos,xSize=xSize,ySize=ySize}
term.setCursorPos(xPos,yPos)
term.setBackgroundColor(buttonColor)
for a = 1,ySize do
for b = 1,xSize do
write(" ")
end
term.setCursorPos(xPos,yPos+a)
end
term.setCursorPos(xPos + (xSize / 2) - (#text / 2),yPos + (ySize / 2))
term.setTextColor(textColor)
write(text)
end
function checkButton(xPos,yPos,name)
if xPos >= buttons[name].xPos and xPos <= buttons[name].xPos + buttons[name].xSize - 1 and yPos >= buttons[name].yPos and yPos <= buttons[name].yPos + buttons[name].ySize - 1 then
return true
else
return false
end
end
function window(xPos,yPos,xSize,ySize,title)
windowIsOpen = true
drawDesktop()
term.setCursorPos(xPos,yPos)
term.setBackgroundColor(colors.blue)
for a = 1,xSize do
write(" ")
end
term.setCursorPos(xPos,yPos+(xSize/2)-(#title/2))
addButton(xPos+xSize-1,yPos,1,1,colors.red,colors.white,"X","exit")
for a = 1,ySize do
term.setCursorPos(xPos,yPos+a)
for b = 1,xSize do
write(" ")
end
end
end
function run()
startMenu()
window(3,5,10,1,"Run","")
end
function startMenu()
if not startMenuIsOpen then
term.setBackgroundColor(colors.cyan)
term.setCursorPos(1,19-(#startMenuItems*2))
for a = 1,#startMenuItems*2 do
print(" ")
end
for a = 1,#startMenuItems do
local b,c = string.find(startMenuItems[a],":")
addButton(1,19-(#startMenuItems*2)+((a-1)*2),8,1,colors.blue,colors.white,string.sub(startMenuItems[a],1,c-1),string.sub(startMenuItems[a],1,c-1))
print("")
print("--------")
end
startMenuIsOpen = true
else
drawDesktop()
end
end
drawDesktop()
while true do
local e,button,x,y = os.pullEvent("mouse_click")
--Start Menu Button
if checkButton(x,y,"start") then
term.setCursorPos(1,1)
startMenu()
end
--Start Menu Items
for a = 1,#startMenuItems do
local b,c = string.find(startMenuItems[a],":")
if checkButton(x,y,string.sub(startMenuItems[a],1,c-1)) then
if string.sub(startMenuItems[a],c+1,#startMenuItems[a]) == "*" then
run()
else
shell.run(string.sub(startMenuItems[a],c+1,#startMenuItems[a]))
end
end
end
--Exit button
if checkButton(x,y,"exit") and windowIsOpen then
drawDesktop()
end
end
Thank You!