4 posts
Posted 25 June 2012 - 05:16 AM
ok so i want to write a program that is like the door lock program but with a twist.
what i want is if i get the correct password i can either turn on or off the redstone current like a switch or do the following program that is based off the regular open door program that will shutthe current off only if it is already on.
local side = "left"
local password = "bacon"
local opentime = 90000000
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
if rs.setOutput(side,true) then
rs.setOutput(side,false)
else
rs.setOutput(side,true)
sleep(opentime)
rs.setOutput(side,false)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
sleep(2)
os.reboot()
end
62 posts
Location
Behind you
Posted 25 June 2012 - 01:08 PM
I see you missed a few "End"s in that program.
And it is possible to make it like a switch. You listen for the "char" event, and you use a letter or number for on/off.
Hope this helped.
1548 posts
Location
That dark shadow under your bed...
Posted 25 June 2012 - 02:28 PM
the correct toggle code for the output is:
if rs.getOutput(side) then
rs.setOutput(side,false)
else
rs.setOutput(side,true)
end
that will toggle the redstone output when run, give it a try
134 posts
Location
Salt Lake, UT
Posted 25 June 2012 - 03:00 PM
the correct toggle code for the output is:
if rs.getOutput(side) then
rs.setOutput(side,false)
else
rs.setOutput(side,true)
end
that will toggle the redstone output when run, give it a try
But we won't know if it is true or not… i needs to be
if. rs.getOutput(side) == true then
rs.setOutput(side, false)
else
rs.setOutput(side, true)
1548 posts
Location
That dark shadow under your bed...
Posted 25 June 2012 - 03:02 PM
you should also try using bundled cables to toggle multiple door sets simultaneously. here is the one I use
Spoiler
local side="back"
local cols
local white
local orange
local magenta
local lblue
local yellow
local lime
local pink
local gray
local lgray
local cyan
local function setside()
term.clear()
term.setCursorPos(1,1)
print("Enter side of bundled cable")
side=io.read()
if side=="" then side="back" end
end
local function update()
cols=redstone.getBundledOutput(side)
white=colors.test(cols,colors.white)
orange=colors.test(cols,colors.orange)
magenta=colors.test(cols,colors.magenta)
lblue=colors.test(cols,colors.lightBlue)
yellow=colors.test(cols,colors.yellow)
lime=colors.test(cols,colors.lime)
pink=colors.test(cols,colors.pink)
gray=colors.test(cols,colors.gray)
lgray=colors.test(cols,colors.lightGray)
cyan=colors.test(cols,colors.cyan)
end
local function toggle(num)
local selectedcol=nil
local usecol=nil
if num=="1" then selectedcol=colors.white
elseif num=="2" then selectedcol=colors.orange
elseif num=="3" then selectedcol=colors.magenta
elseif num=="4" then selectedcol=colors.lightBlue
elseif num=="5" then selectedcol=colors.yellow
elseif num=="6" then selectedcol=colors.lime
elseif num=="7" then selectedcol=colors.pink
elseif num=="8" then selectedcol=colors.gray
elseif num=="9" then selectedcol=colors.lightGray
elseif num=="0" then selectedcol=colors.cyan
end
if selectedcol then
if colors.test(cols,selectedcol) then
usecol=colors.subtract(cols,selectedcol)
else
usecol=colors.combine(cols,selectedcol)
end
redstone.setBundledOutput(side, usecol)
end
end
while true do
term.clear()
term.setCursorPos(1,1)
update()
io.write("white (1): ") print(white)
io.write("orange (2): ") print(orange)
io.write("magenta (3): ") print(magenta)
io.write("lblue (4): ") print(lblue)
io.write("yellow (5): ") print(yellow)
io.write("lime (6): ") print(lime)
io.write("pink (7): ") print(pink)
io.write("gray (8): ") print(gray)
io.write("lgray (9): ") print(lgray)
io.write("cyan (0): ") print(cyan)
local event,key=os.pullEvent("char")
if key=="." then setside() else toggle(key) end
end
When you run it you get a display of which colours are on so then if you press the corresponding number it toggles any door attached to the insulated wire of that colour
134 posts
Location
Salt Lake, UT
Posted 25 June 2012 - 03:04 PM
Or you could use a keycard door. It makes it so that only certain people can get in. this makes it so that you have annother level of security
1548 posts
Location
That dark shadow under your bed...
Posted 25 June 2012 - 03:11 PM
you never need ==true because it automatically assumes that you want to know if a value is true if you don't specify any comparison. give this a try
while turtle.forward() do end --to loop through moving forward until it cannot do so
turtle.up() --to verify that it has actually ended the loop
the turtle will move forward until it encounters an obstacle and then move up to show us that the condition worked without saying 'while turtle.forward()==true'
1548 posts
Location
That dark shadow under your bed...
Posted 25 June 2012 - 03:59 PM
it also checks if a variable has a value assigned to it, that is a very useful function
4 posts
Posted 25 June 2012 - 07:24 PM
read below
4 posts
Posted 25 June 2012 - 08:28 PM
this worked i thankyou for all the help.
i do however have one more problem…
after i type in the password and it gives me the "your in" sign… it gives me the "your in" sign for the whole (opentime). now it probably is simple but im so so tired and hoenstly can figure it out on my own …. lame i know.
if i fugure it out i will put up the new working pic :P/>/>
thank you guys for all your help so far :)/>/>
1604 posts
Posted 25 June 2012 - 08:37 PM
I'm not sure if this is what you want, but this program will switch the redstone output when you enter the password:
local side = "left"
local password = "bacon"
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
while true do
clear()
write("Password: ")
local input = read("*")
if input == password then
clear()
print("Password correct!")
rs.setOutput(side, not rs.getOutput(side))
else
clear()
print("Password incorrect!")
end
sleep(2)
end
You should protect it against Ctrl-T, so no one can use it without the password.
4 posts
Posted 26 June 2012 - 05:05 AM
I'm not sure if this is what you want, but this program will switch the redstone output when you enter the password:
local side = "left"
local password = "bacon"
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
while true do
clear()
write("Password: ")
local input = read("*")
if input == password then
clear()
print("Password correct!")
rs.setOutput(side, not rs.getOutput(side))
else
clear()
print("Password incorrect!")
end
sleep(2)
end
You should protect it against Ctrl-T, so no one can use it without the password.
yes this worked thanks so much. solved my problems with turning it on and off and i did the code with the anti-control t program in it as well
thanks fir all your support :P/>/>