4 posts
Location
Alaska!
Posted 16 November 2012 - 06:27 PM
Hello there. I'm new to both Lua AND ComputerCraft. I have done some thigns in C before, but I'm also fairly new at that as well. Please, do not run a trident through me for this. it is the first thing I've ever tried to code (without a cheatsheet in front of me, in Lua), and is mostly a heavily modifed *and also broken* version of this:
http://computercraft..._Protected_DoorSo anyway, here it is, in all it's non functioning glory:
print ("Property of Convex")
print ("PLEASE ENTER CONFIRMATION CODE:")
input = read ("*")
if input == password then
textutils.slowWrite ("...")
sleep (1)
return (2)
print ("ACCESS GRANTED")
else
print ("ERROR:INCCORECT CODE")
end
Please, help a newb out? :/
by the way, it says I need to put in an end at line 8 to end the if in line 4…….
Edit: Danke Lyqyd for the code tags :)/>/> I had no idea how to put those in >_<
Edited by
8543 posts
Posted 16 November 2012 - 06:36 PM
What you had:
print ("Property of Convex")
print ("PLEASE ENTER CONFIRMATION CODE:")
input = read ("*")
if input == password then
textutils.slowWrite ("...")
sleep (1)
return (2) --return needs to be the last statement of the block, and you do not need the parentheses.
print ("ACCESS GRANTED")
else
print ("ERROR:INCCORECT CODE")
end
Maybe try this instead:
while true do --loop until they get it right (if this is desired, otherwise remove this line and the final end).
term.clear()
term.setCursorPos(1,1)
print ("Property of Convex")
print ("PLEASE ENTER CONFIRMATION CODE:")
input = read("*")
if input == password then
textutils.slowWrite("...")
print ("ACCESS GRANTED")
--We move the print here so it can be seen before we return.
sleep(1)
break --break/return needs to be the last statement of the block, and you do not need the parentheses.
else
print ("ERROR:INCCORECT CODE")
sleep(1)
end
end
If you're having a specific problem after these changes, be sure to let us know!
4 posts
Location
Alaska!
Posted 16 November 2012 - 06:47 PM
Well, I made the changes real quick….. I've gotten an even more confusing error XD
No matter what I put in as the code, it simply does nothing and brings me back to the same line.
while true do
term.clear()
term.setCursorPos(1,1)
print ("Property of Convex")
print ("PLEASE ENTER CONFIRMATION CODE:")
input = read ("*")
if input == math then
textutils.slowWrite ("...")
print ("ACCESS GRANTED")
sleep (1)
break
else
print ("ERROR:INCCORECT CODE")
sleep (1)
end
end
edit: annnddddd I broke the code tags :I
8543 posts
Posted 16 November 2012 - 06:51 PM
The second one is . Ah, I see the problem.
while true do
term.clear()
term.setCursorPos(1,1)
print ("Property of Convex")
print ("PLEASE ENTER CONFIRMATION CODE:")
input = read ("*")
if input == "math" then
textutils.slowWrite ("...")
print ("ACCESS GRANTED")
sleep (1)
break
else
print ("ERROR:INCCORECT CODE")
sleep (1)
end
end
You need to have string literals in quotes, so math wouldn't work, but "math" will. Without the quotes, it thinks you're comparing to a variable named math (in this case, the math library table, coincidentally).
4 posts
Location
Alaska!
Posted 16 November 2012 - 07:01 PM
Ah, awesome :)/>/> Thank you a ton for your help :D/>/> My orignally destroyed code mostly works now :D/>/> Except, it won't display the error message. as a side note, It also like to put both access granted and the three periods all on the same line,all at once, where I'd prefer them to be seperate lines. could I fix that by using textutils.slowPrint instead? o:
edit: wow I'm asking for a ton XD
1214 posts
Location
The Sammich Kingdom
Posted 16 November 2012 - 09:30 PM
Ah, awesome :)/>/> Thank you a ton for your help :D/>/> My orignally destroyed code mostly works now :D/>/> Except, it won't display the error message. as a side note, It also like to put both access granted and the three periods all on the same line,all at once, where I'd prefer them to be seperate lines. could I fix that by using textutils.slowPrint instead? o:
edit: wow I'm asking for a ton XD
Yes. Write, writes to the end of the string while prints writes to the next line of the last string.
4 posts
Location
Alaska!
Posted 17 November 2012 - 04:04 PM
Ah, thanks for that :)/>/> a lot of the resources I've found have been farily dry or confusing, this has helped me a ton!