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

Coding Help.

Started by ChaddJackson12, 29 July 2012 - 12:20 AM
ChaddJackson12 #1
Posted 29 July 2012 - 02:20 AM
Hello… I have another question concerning a boot disk… I have followed what I thought would be a right way to go with the "If/Else" Statements, but it isn't working out for me with over 3 options for an input… Anyway here is the code!

On the screen in computercraft it says: For input string: "_2")

I am new to coding, so I cannot find the problem, sorry.



os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
write("Thank you for purchasing Light Control V1.0! nnThis product is designed to give you control over your lights! nnTo begin I need to know which version that you would like to install... nnPassword or No Password protection? nType Pass or NoPass or Cancel nn> ")
local input = read()

if input == "Pass" then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Installing Light Control Password Edition... Please Wait...")
os.sleep(4)
fs.delete("Lights")
fs.copy("disk/program", "Lights")
write("nnLight Control Password Edtion Installed Successfully!")
os.sleep(1)
write("nnThe Disk Will Now Eject")
os.sleep(2)
disk.eject("right")
os.sleep(1)
term.clear()
term.setCursorPos(1,1)
write("Enjoy Using Light Control v1.0!")
os.sleep(1)
write("nnYour Computer Will Now Reboot!")
os.sleep(2)
end

if input == "NoPass" then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Installing Light Control Password Free Edition")
os.sleep(4)
fs.delete("Lights")
fs.copy("disk/program2", "Lights")
write("nnLight Control Password Free Edition Installed Successfully!")
os.sleep(1)
write("nnThe Disk Will Now Eject")
os.sleep(2)
disk.eject("right")
os.sleep(1)
term.clear()
term.setCursorPos(1,1)
write("enjoy Using Light Control v1.0!")
os.sleep(1)
write("nnYour Computer Will Now Reboot!")
os.sleep(2_
end

if input == "Cancel" Then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Cancelling Installation... Please Wait...")
os.sleep(4)
write("nnCancellation Complete!")
os.sleep(2)
write("The Disk Will Now Eject")
os.sleep(1)
disk.eject("right")
os.sleep(1)
write("nnYour Computer Will Now Reboot")
os.sleep(2)
os.reboot()
end

else
write("ERROR! You Have Entered An Incorrect Answer! Try Again!")
os.sleep(1)
write("nnYour Computer Will Now Reboot!")
end
ChaddJackson12 #2
Posted 29 July 2012 - 02:22 AM
Also, since I am new to using Lua, I can't really help with the non indenting for computercraft. I am not that far yet.
Lasere123456 #3
Posted 29 July 2012 - 01:14 PM
replaced write with print
and fixed one misspelling


os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("Thank you for purchasing Light Control V1.0! nnThis product is designed to give you control over your lights! nnTo begin I need to know which version that you would like to install... nnPassword or No Password protection? nType Pass or NoPass or Cancel nn> ")
local input = read()
if input == "Pass" then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Installing Light Control Password Edition... Please Wait...")
os.sleep(4)
fs.delete("Lights")
fs.copy("disk/program", "Lights")
print("nnLight Control Password Edtion Installed Successfully!")
os.sleep(1)
print("nnThe Disk Will Now Eject")
os.sleep(2)
disk.eject("right")
os.sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Enjoy Using Light Control v1.0!")
os.sleep(1)
print("nnYour Computer Will Now Reboot!")
os.sleep(2)
end
if input == "NoPass" then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Installing Light Control Password Free Edition")
os.sleep(4)
fs.delete("Lights")
fs.copy("disk/program2", "Lights")
print("nnLight Control Password Free Edition Installed Successfully!")
os.sleep(1)
print("nnThe Disk Will Now Eject")
os.sleep(2)
disk.eject("right")
os.sleep(1)
term.clear()
term.setCursorPos(1,1)
print("enjoy Using Light Control v1.0!")
os.sleep(1)
print("nnYour Computer Will Now Reboot!")
os.sleep(2) -- <----------------------------------------------------------------- found a error her
end
if input == "Cancel" Then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Cancelling Installation... Please Wait...")
os.sleep(4)
print("nnCancellation Complete!")
os.sleep(2)
print("The Disk Will Now Eject")
os.sleep(1)
disk.eject("right")
os.sleep(1)
print("nnYour Computer Will Now Reboot")
os.sleep(2)
os.reboot()
end
else
print("ERROR! You Have Entered An Incorrect Answer! Try Again!")
os.sleep(1)
print("nnYour Computer Will Now Reboot!")
end
Tiin57 #4
Posted 29 July 2012 - 01:20 PM
What this code does is allow the passwords to be entered in sequence. To have if x or y or z, use elseif. Like so:

if tiin == life then
print("Lol")
elseif tiin == "cheese" then
print("Duh")
elseif tiin == "moron" then
print("Sort of.")
else
end
Lyqyd #5
Posted 29 July 2012 - 06:58 PM
Yep, you need to use elseif:


os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("Thank you for purchasing Light Control V1.0! nnThis product is designed to give you control over your lights! nnTo begin I need to know which version that you would like to install... nnPassword or No Password protection? nType Pass or NoPass or Cancel nn> ")
local input = read()
if input == "Pass" then
    term.clear()
    term.setCursorPos(1,1)
    textutils.slowPrint("Installing Light Control Password Edition... Please Wait...")
    os.sleep(4)
    fs.delete("Lights")
    fs.copy("disk/program", "Lights")
    print("nnLight Control Password Edtion Installed Successfully!")
    os.sleep(1)
    print("nnThe Disk Will Now Eject")
    os.sleep(2)
    disk.eject("right")
    os.sleep(1)
    term.clear()
    term.setCursorPos(1,1)
    print("Enjoy Using Light Control v1.0!")
    os.sleep(1)
    print("nnYour Computer Will Now Reboot!")
    os.sleep(2)
elseif input == "NoPass" then
    term.clear()
    term.setCursorPos(1,1)
    textutils.slowPrint("Installing Light Control Password Free Edition")
    os.sleep(4)
    fs.delete("Lights")
    fs.copy("disk/program2", "Lights")
    print("nnLight Control Password Free Edition Installed Successfully!")
    os.sleep(1)
    print("nnThe Disk Will Now Eject")
    os.sleep(2)
    disk.eject("right")
    os.sleep(1)
    term.clear()
    term.setCursorPos(1,1)
    print("enjoy Using Light Control v1.0!")
    os.sleep(1)
    print("nnYour Computer Will Now Reboot!")
    os.sleep(2)
elseif input == "Cancel" Then
    term.clear()
    term.setCursorPos(1,1)
    textutils.slowPrint("Cancelling Installation... Please Wait...")
    os.sleep(4)
    print("nnCancellation Complete!")
    os.sleep(2)
    print("The Disk Will Now Eject")
    os.sleep(1)
    disk.eject("right")
    os.sleep(1)
    print("nnYour Computer Will Now Reboot")
    os.sleep(2)
    os.reboot()
else
    print("ERROR! You Have Entered An Incorrect Answer! Try Again!")
    os.sleep(1)
    print("nnYour Computer Will Now Reboot!")
end
ChaddJackson12 #6
Posted 29 July 2012 - 10:05 PM
Ok thanks guys. I am tried elseif too but I guess it was a misspelling. :3
ChaddJackson12 #7
Posted 30 July 2012 - 04:20 PM
What this code does is allow the passwords to be entered in sequence. To have if x or y or z, use elseif. Like so:

if tiin == life then
print("Lol")
elseif tiin == "cheese" then
print("Duh")
elseif tiin == "moron" then
print("Sort of.")
else
end
Nice code lol.
Laserman34170 #8
Posted 30 July 2012 - 11:23 PM
Ok thanks guys. I am tried elseif too but I guess it was a misspelling. :3

No, not a mispelling, but a syntax error(sort of). The else at the end wasn't "connected" to an if loop so it messed up.