Posted 02 July 2014 - 07:32 PM
I'm currently working on an OS, and I wanted to add a button that allows a user to launch CraftOS. I tried experimenting with the multishell API so the OS could still be open, but I'm not entirely certain on how to use it. I currently have this:
It does this just fine; it launches a second shell with the terminal, while maintaining the original. However, it also gives me an error that says "OS.MAIN: 66: attempt to compare nil with number". I understand what the error means, but I have no idea why it's even going to that section of the script. This is all the related code:
Any help would be much appreciated. Also, if I'm unclear about something (which is quite common when I ask for help) please tell me so I may clarify!
local tabID = multishell.launch({}, "rom/programs/shell")
multishell.setTitle(tabID, "Shell")
It does this just fine; it launches a second shell with the terminal, while maintaining the original. However, it also gives me an error that says "OS.MAIN: 66: attempt to compare nil with number". I understand what the error means, but I have no idea why it's even going to that section of the script. This is all the related code:
while true do
local event, button, x, y = os.pullEventRaw()
if slc == 0 then
if event == "mouse_click" then
if x >= 2 and x <= 8 and y == 1 and button == 1 then --Start menu
GUI_API.drawMenuStart()
slc = 1
elseif x >= 17 and x <= 25 and y == 1 and button == 1 then --Console
local tabID = multishell.launch({}, "rom/programs/shell")
multishell.setTitle(tabID, "Shell")
slc = 1
elseif x >= 27 and x <= 33 and y == 1 and button == 1 then --Games
GUI_API.drawMenuGames()
slc = 1
elseif x >= 2 and x <= 5 and y >= 3 and y <= 9 and button == 1 then --Icon
shell.run("file")
elseif x >= 1 and y >=2 and button == 2 then slc = 2 --For right clicks
if x >= 38 then
contextX = 38
end
if y >= 14 then
contextY = 14
end
if x <= 38 then
contextX = x
end
if y <= 14 then
contextY = y
end
GUI_API.drawMenuContext(contextX, contextY)
else
GUI_API.drawDesktop()
end
end
elseif slc == 1 then
if x >= 1 and x <= 11 and y == 3 and button == 1 then slc = 0 --For Shutdown button
os.shutdown() --THIS IS LINE 66!
elseif x >= 1 and x <= 11 and y == 4 and button == 1 then slc = 0 --For Restart button
os.reboot()
elseif x >= 1 and x <= 11 and y == 5 and button == 1 then slc = 0 --For the LuaIDE button
shell.run("LuaIDE")
elseif x >= 1 and x <= 11 and y == 6 and button == 1 then slc = 0 --For the New account button
shell.run("new_account")
elseif x >= 1 and x <= 11 and y == 8 and button == 1 then slc = 0 --For the Uninstall button
shell.run("uninstall")
else
slc = 0
GUI_API.drawDesktop()
end
elseif slc == 2 then
if x >= contextX and x <= contextX+13 and y == contextY+1 and button == 1 then slc = 0 --Edit GUI
shell.run("edit", "GUI_API")
GUI_API.drawDesktop()
elseif x >= contextX and x <= contextX+13 and y == contextY+2 and button == 1 then slc = 0 --Edit Background
shell.run("paint", ".background")
GUI_API.drawDesktop()
elseif x >= contextX and x <= contextX+13 and y == contextY+3 and button == 1 then slc = 0 --Edit icon
shell.run("paint", ".icons")
GUI_API.drawDesktop()
elseif x >= contextX and x <= contextX+13 and y == contextY+4 and button == 1 then slc = 0 --File Manager
shell.run("file") --Does not exist yet
GUI_API.drawDesktop()
else slc = 0
GUI_API.drawDesktop()
end
end
end
Any help would be much appreciated. Also, if I'm unclear about something (which is quite common when I ask for help) please tell me so I may clarify!