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

os,pullevent

Started by Crowdy199, 22 December 2012 - 08:32 AM
Crowdy199 #1
Posted 22 December 2012 - 09:32 AM
ok guys i am making an os , so you no how when you boot your computer you get the back screen where u selected to run windows normaly? well in my computercraft os i am trying to make the boot like that where u can select my os or regular computercraft: heres what i dont no i want to make it so that instead of typing witch os u want to run becuase i no how to do that i want to make it so if u click the down arrow or up arrow it selects it and it runs the one u have selected when u hit enter plz help i am new to os.pullevent


My Code Now:
shell.run("clear")
print(" Boot Screen")
print(" ") - to skip line
print("Os1")
print("os2")
print("") - skip line
write("What Would U like To Run")
input = read()
if input == "Os1" then
shell.run("clear")
print("Running Os 1") - the os code will be here
else
if input == Os2 then
shell.run("clear")
print("ComputerCraft")
else
print("Error Unknown OS")
end
end
Goof #2
Posted 22 December 2012 - 09:52 AM
your code (fixed)

(this is not for arrow keys.)
Spoiler


shell.run("clear")
print(" Boot Screen")
print("\nOs1")
print("os2")
write("\nWhat Would U like To Run") -- "\n" skips a line
local input = read()
if input == "Os1" then
shell.run("clear")
print("Running Os 1") - the os code will be here
elseif input == "Os2" then
shell.run("clear")
print("ComputerCraft")
else
Error("Unknown OS")
end

This is for Arrow keys :
Spoiler


local running = true
local selectedItem = 1
local x, y = term.getSize()
local yourOsName = "" -- edit this to the name of your OS... (if the file is named OS1 then type "OS1") --

-- This is copied from another post --

function clear(posX, posY)
term.clear()
if posX == nil then
if posY == nil then
term.setCursorPos(1,1)
else
term.setCursorPos(posX, posY)
end
end
end

clear()
print("Please choose an OS!")

function Menu()
--[[Actions]]--
function Os1()
clear()
running = false
print("Running "..yourOsName)
shell.run(yourOsName)
end

function Os2()
clear()
running = false
print("CraftOS v1.45")
end
--[[Menu]]--
mainMenu = {
[1] = { text = "Os1", handler = Os1 },
[2] = { text = "Os2", handler = Os2 }
}


--[[print]]--

function printMenu( menu )
  for i = 1, #menu do
	if i == selectedItem then
	  print(">> "..menu[i].text.." <<")
else
	  print("   "..menu[i].text.."   ")
end
  end
end  

--[[handler]]--

function onKeyPressed( key, menu )
  if key == 28 then
	onItemSelected( menu )
  elseif key == 200 then
	if selectedItem > 1 then
selectedItem = selectedItem - 1
end
  elseif key == 208 then
	if selectedItem < #menu then
selectedItem = selectedItem + 1
end
  end
end  

function onItemSelected( menu )
menu[selectedItem].handler()
end

--[[Main Method]]--
selectedItem = 1
while running do
for i = 2,18 do
term.setCursorPos(1,i)
term.clearLine()
end
term.setCursorPos(1,2)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed( key, mainMenu )
end
end

Menu()

i will edit this post, in a few mins, and then tell you the Arrow keys support :D/> is now done :D/>
i Hope i could help
Crowdy199 #3
Posted 22 December 2012 - 10:02 AM
thanks
Goof #4
Posted 22 December 2012 - 10:10 AM
Now i've edited the post :)/> i hope i could help you :D/>