Jump to content




Piston Door Help


  • You cannot reply to this topic
7 replies to this topic

#1 072608

  • Members
  • 24 posts

Posted 14 May 2012 - 01:28 AM

I've made this program it Opens and closes and Piston Door (3*3)
All this works, i want make stay in the program unless you use the 3 command
I've try but it either Mess up or won't work

shell.run("clear")
print (" Panic Room Door control 0.2v")
print (" ----------------------------")
print (" [1] Open Door ")
print (" [2] Close Door ")
print (" [3] Exit ")
print (" [4] Shutdown Computer ")
input = read.io()
yes = "1"
no  = "2"
yo  = "3"
la  = "4"
if input == yes then
redstone.setOutput ("back", false)
shell.run("startup")
end
if input == no then
redstone.setOutput ("back", true)
shell.run("startup")
end
if input == yo then
shell.run("clear")
function mainmenu()
end
end
if input == la then
sleep(1)
os.shutdown()
end



#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 14 May 2012 - 01:33 AM

From what I can tell if option 3 is selected you want it to reprint the menu?

If so just place it in a while loop. the function that you have declared in the if state does basically nothing so remove it. Try this.

while true do -- start infinite loop
shell.run("clear")
print (" Panic Room Door control 0.2v")
print (" ----------------------------")
print (" [1] Open Door ")
print (" [2] Close Door ")
print (" [3] Exit ")
print (" [4] Shutdown Computer ")
input = read.io()
yes = "1"
no  = "2"
yo  = "3"
la  = "4"
if input == yes then
redstone.setOutput ("back", false)
shell.run("startup")
break -- break loop before continuing
end
if input == no then
redstone.setOutput ("back", true)
shell.run("startup")
break -- break the loop before proceeding
end
if input == yo then
sleep(0) -- to avoid an error
if input == la then
sleep(1)
os.shutdown()

end
end -- end the loop

If you want use functions then it should look something like
function mainmenu()
--insert code for mainmenu here
end

mainmenu() -- to call the function


#3 Zalerinian

  • New Members
  • 68 posts
  • LocationThe Internet

Posted 14 May 2012 - 03:06 AM

If you're trying to exit the program and go to the CraftOS screen when you select the third option, the code would not be the function for the main menu, but rather simply return.

shell.run("clear")
print (" Panic Room Door control 0.2v")
print (" ----------------------------")
print (" [1] Open Door ")
print (" [2] Close Door ")
print (" [3] Exit ")
print (" [4] Shutdown Computer ")
input = read.io()
yes = "1"
no  = "2"
yo  = "3"
la  = "4"
if input == yes then
redstone.setOutput ("back", false)
shell.run("startup")
end
if input == no then
redstone.setOutput ("back", true)
shell.run("startup")
end
if input == yo then
shell.run("clear")
return
end
end
if input == la then
sleep(1)
os.shutdown()
end

this will simply shut down the PROGRAM, NOT the COMPUTER

#4 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 15 May 2012 - 03:58 AM

If you're trying to get the program to exit without shutting down the computer, you could try the previous poster's code ^^ or this little snippet:
shell.run("clear")
function printMainMenu()
print (" Panic Room Door control 0.2v")
print (" ----------------------------")
print (" [1] Open Door ")
print (" [2] Close Door ")
print (" [3] Exit ")
print (" [4] Shutdown Computer ")
end
while true do
shell.run("clear") -- Moving this line up here will simply clear the screen every time until the loop is broken
printMainMenu()

input = read.io()
yes = "1"
no  = "2"
yo  = "3"
la  = "4"

if input == yes then
redstone.setOutput ("back", false)
shell.run("startup")
elseif input == no then
redstone.setOutput ("back", true)
shell.run("startup")
end
elseif input == yo then break
-- the break keyword will 'break' or end/exit the current loop. Our while true loop will stop,
-- the program will end, and the user will be prompted with the familiar CraftOS screen.
elseif input == la then
sleep(1)
os.shutdown()
end

Similarly, if you wanted to get the computer to just reboot so the user would be prompted with the boot up screen ("CraftOS 1.3 >_") then you could try this:
shell.run("clear")
function printMainMenu()
print (" Panic Room Door control 0.2v")
print (" ----------------------------")
print (" [1] Open Door ")
print (" [2] Close Door ")
print (" [3] Exit ")
print (" [4] Shutdown Computer ")
end
while true do
shell.run("clear") -- Moving this line up here will simply clear the screen every time until the loop is broken
printMainMenu()

input = read.io()
yes = "1"
no  = "2"
yo  = "3"
la  = "4"

if input == yes then
redstone.setOutput ("back", false)
shell.run("startup")
elseif input == no then
redstone.setOutput ("back", true)
shell.run("startup")
end
elseif input == yo then os.reboot()
elseif input == la then
sleep(1)
os.shutdown()
end


#5 MathManiac

  • Members
  • 60 posts
  • LocationWashington, United States

Posted 17 May 2012 - 03:17 AM

Here are some things that can be of mind:

os.shutdown() -- shuts the computer down
os.reboot() -- restarts the computer
return -- if used by itself in lua code OUTSIDE A FUNCTION, then it will end the program.
no -- when it is in the code bar, it looks suspicious... maybe use a different variable such as "novar"

Also, I hate a wall of text. Use indentions, for it not only makes code easier to see, it is good practice.

#6 072608

  • Members
  • 24 posts

Posted 23 May 2012 - 07:50 PM

what I meant was to make not exit out of program when you enter something random

#7 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 May 2012 - 07:57 PM

Use a loop:
local function clear() -- way better that using shell.run("clear")
  term.clear()
  term.setCursorPos(1, 1)
end

while true do
  clear()
  print (" Panic Room Door control 0.2v")
  print (" ----------------------------")
  print (" [1] Open Door ")
  print (" [2] Close Door ")
  print (" [3] Exit ")
  print (" [4] Shutdown Computer ")
  local input = read()
  if input == "1" then
	redstone.setOutput ("back", false)
  elseif input == "2" then
	redstone.setOutput ("back", true)
  elseif input == "3" then
	clear()
	break
  elseif input == "4" then
	print("Goodbye")
	sleep(1)
	os.shutdown()
  end
end
I changed some other things also, like using elseif and the clear function.

#8 072608

  • Members
  • 24 posts

Posted 24 May 2012 - 02:46 AM

thanks MysticT
it does what wanted too do :)/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users