10 posts
Posted 29 December 2012 - 05:14 PM
What I would like to accomplish is a program that basically opens three doors, one at a time. Here is the raw program"
os.pullEvent = os.pullEventRaw
local opendoor = "a"
local door2 = "b"
local door3 = "c"
term.clear()
term.setCursorPos(1,1)
write ("Enter Command:")
if input == opendoor then
print "Opening door 1"
-This is where I'm stuck. I would want it to go back to the enter command part of the program after the door opens and keep the local door passcodes so that I can enter another code. Any help would be appreciated, Thank you.
P.S: please try to dumb down your answers, as I am rather new to CC :P/>
7 posts
Location
UK
Posted 29 December 2012 - 06:08 PM
This can be achieved using a While loop.
For example:
os.pullEvent = os.pullEventRaw
while true do
local opendoor = "a"
local door2 = "b"
local door3 = "c"
term.clear()
term.setCursorPos(1,1)
write ("Enter Command:")
input = read()
if input == "door 1" then
print("Opening door 1")
elseif input == "door 2" then
print("Opening door 2")
[code]
elseif input == "door 3" then
print("Opening door 3")
[code]
else
print("Command not recognised")
end
end
Once a command has been entered it will respond based on the command then return to the top of the loop when the response (opening a door etc) has been completed.
2088 posts
Location
South Africa
Posted 29 December 2012 - 10:46 PM
Try avoiding adding the set strings in the loops, and for the part you got stuck, you can use elseif's for more and more commands
os.pullEvent = os.pullEventRaw
door1Pass = "a"
door2Pass = "b"
door3Pass = "c"
while true do
term.clear()
term.setCursorPos(1,1)
print("Enter Command: ")
write(" > ")
input = read()
if input == door1Pass then
print("Opening door 1")
-- Redstone code to open door 1
elseif input == door2Pass then
print("Opening door 2")
-- Redstone code to open door 2
elseif input == door3Pass then
print("Opening door 3")
-- Redstone code to open door 3
else
print("Invalid command.")
end
end
10 posts
Posted 30 December 2012 - 10:41 AM
well, I tried the while true do command, but when I enter a, it doesn't show the text "Opening door ". instead, it immediately jumps back to the Enter Command: bit. I would want it to display the Enter Command" bit, but also show the previous text
10 posts
Posted 30 December 2012 - 04:31 PM
ah nvm, I figured it out :)/>
2088 posts
Location
South Africa
Posted 30 December 2012 - 09:50 PM
Oh woops, just add a sleep(1.5) just before the last end :P/>