This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
JamesIkanov's profile picture

Horrendously Newbie Qeustions

Started by JamesIkanov, 16 November 2012 - 05:27 PM
JamesIkanov #1
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_Door


So 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
Lyqyd #2
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!
JamesIkanov #3
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
Lyqyd #4
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).
JamesIkanov #5
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
Sammich Lord #6
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.
JamesIkanov #7
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!