Jump to content




Coding Help.

game computer media

7 replies to this topic

#1 ChaddJackson12

  • Members
  • 264 posts

Posted 29 July 2012 - 01: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


#2 ChaddJackson12

  • Members
  • 264 posts

Posted 29 July 2012 - 01: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.

#3 Lasere123456

  • Members
  • 30 posts

Posted 29 July 2012 - 12: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


#4 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 29 July 2012 - 12: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


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 29 July 2012 - 05: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


#6 ChaddJackson12

  • Members
  • 264 posts

Posted 29 July 2012 - 09:05 PM

Ok thanks guys. I am tried elseif too but I guess it was a misspelling. :3

#7 ChaddJackson12

  • Members
  • 264 posts

Posted 30 July 2012 - 03:20 PM

View Posttiin57, on 29 July 2012 - 12:20 PM, said:

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.

#8 Laserman34170

  • New Members
  • 34 posts
  • LocationProgramming Land

Posted 30 July 2012 - 10:23 PM

View PostChaddJackson12, on 29 July 2012 - 09:05 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users