Posted 13 October 2013 - 03:05 AM
I am making an os and Im getting an error with io
"io: 47: Unsupported format"
Here is my code
Thank You! :D/>
"io: 47: Unsupported format"
Here is my code
local settings = {
backgroundColor = colors.pink,
toolBarColor = colors.blue,
startMenuButtonColor = colors.green
}
local buttons = {}
local startMenuItems = {
"Restart:reboot",
"Shutdown:shutdown",
"Run:*"
}
local startMenuIsOpen = false
local windowIsOpen = false
function drawDesktop()
term.setBackgroundColor(settings.backgroundColor)
term.clear()
term.setCursorPos(1,19)
term.setBackgroundColor(settings.toolBarColor)
term.clearLine()
addButton(1,19,7,1,settings.startMenuButtonColor,colors.white,"[START]","start")
windowIsOpen = false
startMenuIsOpen = false
end
function saveSettings()
local file = assert(io.open("settings","w"))
file:write(textutils.serialize(settings))
io.close("settings")
end
function loadSettings()
local file = io.open("settings","r")
settings = textutils.unserialize(file:read(1))
io.close("settings")
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,text)
drawDesktop()
windowIsOpen = true
term.setCursorPos(xPos,yPos)
term.setBackgroundColor(colors.blue)
for a = 1,xSize do
write(" ")
end
term.setCursorPos(xPos+(xSize/2)-(#title/2),yPos)
write(title)
term.setCursorPos(xPos,yPos+(xSize/2)-(#title/2))
addButton(xPos+xSize-1,yPos,1,1,colors.red,colors.white,"X","exit")
term.setBackgroundColor(colors.cyan)
for a = 1,ySize do
term.setCursorPos(xPos,yPos+a)
for b = 1,xSize do
write(" ")
end
end
term.setCursorPos(xPos+(xSize/2)-(#text/2),yPos+(ySize/2)+1)
write(text)
end
function run()
startMenu()
window(7,7,35,5,"Run","")
term.setBackgroundColor(colors.white)
term.setCursorPos(9,10)
write(" ")
term.setCursorPos(9,10)
term.setTextColor(colors.black)
program = read()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
term.clear()
shell.run(program)
sleep(1)
drawDesktop()
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
loadSettings()
startMenu()
window(1,1,1,1,"text","text")
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
--Exit button
if checkButton(x,y,"exit") and windowIsOpen then
drawDesktop()
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
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
term.clear()
shell.run(string.sub(startMenuItems[a],c+1,#startMenuItems[a]))
drawDesktop()
end
end
end
end
Thank You! :D/>