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

who can i get it work better ?

Started by poezi, 02 August 2012 - 08:34 AM
poezi #1
Posted 02 August 2012 - 10:34 AM
Hello to everyone i have made a programm to lock and unlock doors.
No i have a problem i have to enter all commands in a raw so if i enter o it wont work i have to enter s first how can i fix that
thx guys :ph34r:/>/>





pass = ("31121997")
eins = ("back")
zwei = ("left")
drei = ("bottom")
vier = ("right")

print("enter password")
if io.read() == pass then
   print("--------------------------------------------------")
   print("MBLS-Military-Base-Lockdown-System-made by poezi")
   print("sytem loaded!   ready for task!		    ")
   print("s= close all doors o= open all doors")
   print("n= emergency lockdown")
   print("1o = open central room")
   print("1s = close central room")  
   print("2o = open batterieroom")
   print("2s = close batterieroom ")
   print("3o = open rooms")
   print("3s = close rooms")
   print("4o = open maindoor")
   print("4s = close maindoor") 
   print("--------------------------------------------------")
   if io.read() == ("s") then
	  redstone.setOutput(eins , true)
	  redstone.setOutput(zwei , true)
	  redstone.setOutput(drei , true)
	  redstone.setOutput(vier , true)
	  write("Alle Schotten dicht")
	  end
   if io.read() == ("o") then
	  redstone.setOutput(eins , false)
	  redstone.setOutput(zwei , false)
	  redstone.setOutput(drei , false)
	  redstone.setOutput(vier , false)
	  write("Alle Schotten offen")
	  end
   if io.read() == ("n") then
	  redstone.setOutput(eins , true)
	  redstone.setOutput(zwei , true)
	  redstone.setOutput(drei , true)
	  redstone.setOutput(vier , true)
	  write("Alles abgeriegel Alarm ausgloest")
	  redstone.setOutput("top" , true)
	  sleep(10)
	  end   
   if io.read() == ("1o") then
	  redstone.setOutput(eins, false)
	  write("central door open")
	  end
   if io.read() == ("1s") then
	  redstone.setOutput(eins, true)
	  write("central door clooser")
	  end
   if io.read() == ("2o") then
	  redstone.setOutput(zwei, false)
	  write("batterie room open")
	  end
   if io.read() == ("2s") then
	  redstone.setOutput(zwei, true)
	  write("batterie room closed")
	  end
   if io.read() == ("3o") then
	  redstone.setOutput(drei, false)
	  write("rooms open")
	  end
   if io.read() == ("3s") then
	  redstone.setOutput(drei, true)
	  write("rooms closed")
	  end
   if io.read() == ("4o") then
	  redstone.setOutput(vier, false)
	  write("maindoor open")
	  end
   if io.read() == ("4s") then
	  redstone.setOutput(vier, true)
	  write("maindoor closed")
	  end		   
end
Luanub #2
Posted 02 August 2012 - 10:55 AM
A couple things. first you want to capture io.read() in a var so..


local input = io.read()

Second since your only doing 1 input its best to only doing 1 if statement to check that input so it should look something like..


local input = io.read()
if input == "s" then
  do s stuff
elseif input == "o" then
  do o stuff
etc....

Same with your password entry I would change it to..

This should work

local pass = ("31121997")
local eins = ("back")
local zwei = ("left")
local drei = ("bottom")
local vier = ("right")

print("enter password")
local passwd = io.read()
if passwd == pass then
   print("--------------------------------------------------")
   print("MBLS-Military-Base-Lockdown-System-made by poezi")
   print("sytem loaded!   ready for task!				   ")
   print("s= close all doors o= open all doors")
   print("n= emergency lockdown")
   print("1o = open central room")
   print("1s = close central room")  
   print("2o = open batterieroom")
   print("2s = close batterieroom ")
   print("3o = open rooms")
   print("3s = close rooms")
   print("4o = open maindoor")
   print("4s = close maindoor")
   print("--------------------------------------------------")
   local input = io.read()
   if input == "s" then
		  redstone.setOutput(eins , true)
		  redstone.setOutput(zwei , true)
		  redstone.setOutput(drei , true)
		  redstone.setOutput(vier , true)
		  write("Alle Schotten dicht")
   elseif input == "o" then
		  redstone.setOutput(eins , false)
		  redstone.setOutput(zwei , false)
		  redstone.setOutput(drei , false)
		  redstone.setOutput(vier , false)
		  write("Alle Schotten offen")
   elseif input == "n" then
		  redstone.setOutput(eins , true)
		  redstone.setOutput(zwei , true)
		  redstone.setOutput(drei , true)
		  redstone.setOutput(vier , true)
		  write("Alles abgeriegel Alarm ausgloest")
		  redstone.setOutput("top" , true)
		  sleep(10)
   elseif input == "1o" then
		  redstone.setOutput(eins, false)
		  write("central door open")
   elseif input == "1s" then
		  redstone.setOutput(eins, true)
		  write("central door clooser")
   elseif input == "2o" then
		  redstone.setOutput(zwei, false)
		  write("batterie room open")
   elseif input == "2s" then
		  redstone.setOutput(zwei, true)
		  write("batterie room closed")
   elseif input == "3o" then
		  redstone.setOutput(drei, false)
		  write("rooms open")
   elseif input == "3s" then
		  redstone.setOutput(drei, true)
		  write("rooms closed")
   elseif input == "4o" then
		  redstone.setOutput(vier, false)
		  write("maindoor open")
   elseif input == "4s" then
		  redstone.setOutput(vier, true)
		  write("maindoor closed")
   end
end

I also changed your vars to local instead of globals. It's always best to use local vars will save you a headache later on. Same with functions if you can make then local as well.
Edited on 02 August 2012 - 08:56 AM
poezi #3
Posted 02 August 2012 - 07:35 PM
thank you very much you helped me allot :ph34r:/>/>
Xenthera #4
Posted 03 August 2012 - 11:36 AM
Sie sollten einsetzen redpower, Statt der Verwendung jedes Gesicht… Viel einfacher :ph34r:/>/>
Luanub #5
Posted 03 August 2012 - 11:42 AM
Sie sollten einsetzen redpower, Statt der Verwendung jedes Gesicht… Viel einfacher :ph34r:/>/>

All posts here are supposed to be in english.

And yes I agree using a bundled cable would be a much easier setup then messing with redstone off 4 different sides of the computer. The code would not be improved a whole bunch as you would be handling colors instead of sides, but the physical setup would be cleaner.
Xenthera #6
Posted 03 August 2012 - 12:28 PM
Sie sollten einsetzen redpower, Statt der Verwendung jedes Gesicht… Viel einfacher :ph34r:/>/>

All posts here are supposed to be in english.

And yes I agree using a bundled cable would be a much easier setup then messing with redstone off 4 different sides of the computer. The code would not be improved a whole bunch as you would be handling colors instead of sides, but the physical setup would be cleaner.

I agree with main posts being english, but if i'm replying to someone who speak another language, it shouldn't matter… If it does you guys have serious issues. No offense.
Luanub #7
Posted 03 August 2012 - 01:15 PM
It's just the first rule listed in the forum guidelines located here http://www.computercraft.info/forums2/index.php?/forum-14/announcement-1-forum-guidelines/

Its so that others that may be searching for help on this same issue can understand as well.