26 posts
Posted 04 April 2012 - 11:32 AM
So I was working on making a piston driven door system with a nice pit to catch the monster that wonder in. I am currently working on the inner door and trying to figure out
how to set the door to open when the switch is thrown.
overall idea is when the inner switch is in the off position the outer door and pit are both open. When the inner switch is in the on position the inner door opens the pit closes. Once I am clear of the outer door I would use a switch to close the doors to keep the baddies from entering. My original idea was this:
if redstone.getInput("right") == true then
redstone.setOutput("top", true)
else
redstone.setOutput("top", false)
end
shell.run(i_door)
as I have discovered I need some sort of way of continually running the program, hence why I chose the shell.run() as a while loop cause a error saying no change detected or something along them lines.
This is as far as I have gotten with the design.. I still need to work in the pit hatch and make sure that the pit is CLOSED before the inner doors open.
9 posts
Posted 04 April 2012 - 12:03 PM
OK, so let's get started with the "let's call the program over and over again" part.
This should do the trick…
while true do
if redstone.getInput("right") then
redstone.setOutput("top", true)
else
redstone.setOutput("top", false)
end
os.sleep(0.1)
end
Note that this is probably not what you want - I've just simply taken your code and ensured that it will run in an infinite loop without murdering your CPU.
Can you please clarify exactly what you're doing?
I'll need to go to bed about now so you'll probably be best to wait until someone else comes along and helps.
26 posts
Posted 04 April 2012 - 12:11 PM
I will post up screens later today when I wake up myself, but essentially I am building a airlock with a lava pit in the center.. When I am in my base the pit is open so any monsters wonder in will fall into the pit. When I am out of the base the pit will be closed and a door will close off the entire area. That outer door will not be tied to the program at all, just a simple switch wired up to the pistons.
1111 posts
Location
Portland OR
Posted 04 April 2012 - 12:36 PM
So if all your looking for is a program that will open a door when the computer receives a redstone signal from a button/switch then what GreaseMonkey posted should do the trick.
Running a program from within itself with shell.run can get messy I would avoid it, and you were probably getting the error due to there not being a sleep in the script. Going to a while true loop with a small sleep should do the trick.
You could also add an pullEvent which would pause the program until it receives a redstone event so its not constantly going.
while true do
os.pullEvent("redstone")
if redstone.getInput("right") then
redstone.setOutput("top", true)
else
redstone.setOutput("top", false)
end
sleep(0.1) -- dont need the os infront of
end
26 posts
Posted 04 April 2012 - 12:42 PM
Okay I decided to go ahead and get the pics up. That code worked perfectly for the door and now I can turn to the rest of the program. I think what I will have is a sleep() to close the lava doors and then I would have the main doors open up
while true do
if redstone.getInput("right") then
redstone.setOutput("bottom", false)
sleep(3)
redstone.setOutput("top", true)
else
redstone.setOutput("top", false)
sleep(1)
redstone.setOutput("bottom", true)
end
os.sleep(0.1)
end
Here is the design that I am using. red plates indicate where the door pistons are at:
26 posts
Posted 04 April 2012 - 12:44 PM
So if all your looking for is a program that will open a door when the computer receives a redstone signal from a button/switch then what GreaseMonkey posted should do the trick.
Running a program from within itself with shell.run can get messy I would avoid it, and you were probably getting the error due to there not being a sleep in the script. Going to a while true loop with a small sleep should do the trick.
You could also add an pullEvent which would pause the program until it receives a redstone event so its not constantly going.
while true do
os.pullEvent("redstone")
if redstone.getInput("right") then
redstone.setOutput("top", true)
else
redstone.setOutput("top", false)
end
sleep(0.1) -- dont need the os infront of
end
I was in the process of posting lol. So I will drop the os off the sleep, but how does the code I just posted look, will it do what I am seeking?
also is there any good beginner tutorials for lua on the net?
1111 posts
Location
Portland OR
Posted 04 April 2012 - 12:49 PM
Its bed time lol If you use the event you can remove the sleep all together. Either one should prevent the error you were getting.
What you posted should work great for what you are trying to do.
I would recommend starting out with the ingame tutorial then going through some of the tutorials that are posted on the forums here, they are pretty helpful and should give you a good amount of knowledge to start with.
And of coarse if you run into problems people here are always happy to help.
26 posts
Posted 04 April 2012 - 12:58 PM
yeah I will pop it on to a disk once I get up and make a new inventory (just fell in my lava : )