Posted 03 April 2012 - 09:49 PM
Hello, im new to computercraft, I've only been using it for a couple days. Im also new to lua, but I think ive picked up pretty well for just starting. Ive made plenty of programs in computercraft, and found/fixed all of my own errors up until now. I have a program, with a built in chance game, that if won, unlocks a door beside it. The game works all the way up until the result is made. It will display the result correctly, but even if the result matches the guess made by the user, the door will not open, and the game acts as if the user guessed incorrectly. Below is the program. Ive left comments on the lines that I think are messed up, if anyone could help me, it'd be much appreciated.
print ("Hello")
print ("What is your name?")
Name = io.read()
print ("Welcome "..Name..".")
sleep(1)
print ("What would you like to do?")
sleep(1)
term.clear()
print ("============================")
print ("=======Please enter:========")
print ("======'Unlock door'=========")
print ("======'Send message'========")
print ("==='Try lucky door game'====")
print ("============================")
choice = io.read()
if choice == "Unlock door" then
print ("Please enter the password:")
pass = io.read()
if pass == "0568" then
redstone.setOutput("right", true )
else
print ("Incorrect password!")
end
elseif choice == "Send message" then
rednet.open("right")
print ("Please enter the message:")
message = io.read()
print ("Sending message…")
sleep(1)
rednet.broadcast(message)
print("Message sent!")
elseif choice == "Try lucky door game" then
print ("Please enter a number between two and twelve.")
guess = io.read()
print ("I will roll two dice, and if they add up to be your number, you win.")
sleep(1)
print ("Your guess is "..guess..".")
sleep(1)
print ("Rolling…")
sleep(1)
num1 = math.random(1,6)
print ("First roll is "..num1.."!")
sleep(1)
print ("Rolling again…")
sleep(1)
num2 = math.random(1,6)
print ("Second roll is "..num2.."!")
sleep(1)
result = num1 + num2
print ("Final result = "..result.."!")
if result == guess then – This is where the program messes up.
redstone.setOutput("left", true ) – Even when the two are equal, the door does not open,
print ("Congragulations!!") – And the congragulations message is not displayed.
sleep(3)
else
print ("Aww, bad luck..") – Only this is, as if the user guessed wrong.
end
end
As I said before, any help would be much appreciated.
~Tus
print ("Hello")
print ("What is your name?")
Name = io.read()
print ("Welcome "..Name..".")
sleep(1)
print ("What would you like to do?")
sleep(1)
term.clear()
print ("============================")
print ("=======Please enter:========")
print ("======'Unlock door'=========")
print ("======'Send message'========")
print ("==='Try lucky door game'====")
print ("============================")
choice = io.read()
if choice == "Unlock door" then
print ("Please enter the password:")
pass = io.read()
if pass == "0568" then
redstone.setOutput("right", true )
else
print ("Incorrect password!")
end
elseif choice == "Send message" then
rednet.open("right")
print ("Please enter the message:")
message = io.read()
print ("Sending message…")
sleep(1)
rednet.broadcast(message)
print("Message sent!")
elseif choice == "Try lucky door game" then
print ("Please enter a number between two and twelve.")
guess = io.read()
print ("I will roll two dice, and if they add up to be your number, you win.")
sleep(1)
print ("Your guess is "..guess..".")
sleep(1)
print ("Rolling…")
sleep(1)
num1 = math.random(1,6)
print ("First roll is "..num1.."!")
sleep(1)
print ("Rolling again…")
sleep(1)
num2 = math.random(1,6)
print ("Second roll is "..num2.."!")
sleep(1)
result = num1 + num2
print ("Final result = "..result.."!")
if result == guess then – This is where the program messes up.
redstone.setOutput("left", true ) – Even when the two are equal, the door does not open,
print ("Congragulations!!") – And the congragulations message is not displayed.
sleep(3)
else
print ("Aww, bad luck..") – Only this is, as if the user guessed wrong.
end
end
As I said before, any help would be much appreciated.
~Tus