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

[UnAnswered] Where did I go wrong?

Started by icecube45, 24 November 2012 - 06:56 AM
icecube45 #1
Posted 24 November 2012 - 07:56 AM
My code is as follows

user = "icecube45"
user1 = "sun1raven"
user2 = "AdmKennedy"
password = "cubeice45"
password1 = "tomcat5"
password2 = "flyer42"
function menu()
term.clear()
term.setCursorPos(1,1)
print("Control Panel V1.0")
print("1: Toggle Dungeon")
print("2: Toggle Quarry")
print("3: Toggle Logo")
print("4: Status Report")
print("5: Log Out")
print("What Would You Like To Do?")
input = read()
if input == "2" then
  print("Under Construction")
  os.sleep(2)
  return menu()
   elseif input == "5" then
	print("Thank You for Using The Control Panel")
	os.sleep(2)
	os.reboot()
   elseif input == "4" then
	c = colors.combine(c, colors.blue)
	if redstone.testBundledInput("left", c) == true then
  logostatus = "Off"
  else
   logostatus = "On"
if redstone.testBundledInput("left", d) == true then
  dungeonstatus = "Off"
  else
   dungeonstatus = "On"
term.clear()
term.setCursorPos(1,1)
print("Dungeon is "..dungeonstatus)
print("Quarry is UNKNOWN")
print("Logo is "..logostatus)
os.sleep(4)
return menu()
end
   elseif input == "1" then
	c = colors.combine(c, colors.blue)
	rs.setBundledOutput("back", c )
os.sleep(1)
c = colors.subtract(c, colors.blue)
rs.setBundledOutput("back", c)
return menu()
   elseif input == "3" then
	d = colors.combine(d, colors.yellow)
	rs.setBundledOutput("back", d )
os.sleep(1)
d = colors.subtract(d, colors.yellow)
rs.setBundledOutput("back", d)
return menu()
   end
end
shell.run("monitor", "top", "face")
term.clear()
term.setCursorPos(1,1)
print("FactoryOS V2.0")
print("Choose A User:")
usercheck = read()
if usercheck == user or usercheck == user1 or usercheck == user2 then
term.clear()
term.setCursorPos(1,1)
print(usercheck.."'s Password:")
passcheck = read("*")
if passcheck == password or passcheck == password1 or passcheck == password2 then
  term.clear()
  term.setCursorPos(1,1)
  menu()
  else
   print("Invalid Password")
   os.reboot()
   end
else
	print("Invalid User")
	os.reboot()
   end


When I press the key 4 however, it just exits the program, any help?
ChunLing #2
Posted 24 November 2012 - 08:29 AM
Proper indentation is your friend.
user = "icecube45"
user1 = "sun1raven"
user2 = "AdmKennedy"
password = "cubeice45"
password1 = "tomcat5"
password2 = "flyer42"
function menu()
    term.clear()
    term.setCursorPos(1,1)
    print("Control Panel V1.0")
    print("1: Toggle Dungeon")
    print("2: Toggle Quarry")
    print("3: Toggle Logo")
    print("4: Status Report")
    print("5: Log Out")
    print("What Would You Like To Do?")
    input = read()
    if input == "2" then
        print("Under Construction")
        os.sleep(2)
        return menu()
    elseif input == "5" then
        print("Thank You for Using The Control Panel")
        os.sleep(2)
        os.reboot()
    elseif input == "4" then
        c = colors.combine(c, colors.blue)
        if redstone.testBundledInput("left", c) == true then
            logostatus = "Off"
        else
            logostatus = "On"
            if redstone.testBundledInput("left", d) == true then
                dungeonstatus = "Off"
            else
                dungeonstatus = "On"
                term.clear()
                term.setCursorPos(1,1)
                print("Dungeon is "..dungeonstatus)
                print("Quarry is UNKNOWN")
                print("Logo is "..logostatus)
                os.sleep(4)
                return menu()
            end
        elseif input == "1" then
            c = colors.combine(c, colors.blue)
            rs.setBundledOutput("back", c )
            os.sleep(1)
            c = colors.subtract(c, colors.blue)
            rs.setBundledOutput("back", c)
            return menu()
        elseif input == "3" then
            d = colors.combine(d, colors.yellow)
            rs.setBundledOutput("back", d )
            os.sleep(1)
            d = colors.subtract(d, colors.yellow)
            rs.setBundledOutput("back", d)
            return menu()
        end
    end
    shell.run("monitor", "top", "face")
    term.clear()
    term.setCursorPos(1,1)
    print("FactoryOS V2.0")
    print("Choose A User:")
    usercheck = read()
    if usercheck == user or usercheck == user1 or usercheck == user2 then
        term.clear()
        term.setCursorPos(1,1)
        print(usercheck.."'s Password:")
        passcheck = read("*")
        if passcheck == password or passcheck == password1 or passcheck == password2 then
            term.clear()
            term.setCursorPos(1,1)
            menu()
        else
            print("Invalid Password")
            os.reboot()
        end
    else
        print("Invalid User")
        os.reboot()
   end
 
Now, does anything about this mess stand out as not being what it's supposed to be?
icecube45 #3
Posted 24 November 2012 - 08:32 AM
I seriously can not figure this out..

the thing is
i want it to determine what to set each variable to
then print what its status is, not only if dungeon is off

Anyone, please?
remiX #4
Posted 24 November 2012 - 10:38 AM
Try this:

Spoiler
user = "icecube45"
user1 = "sun1raven"
user2 = "AdmKennedy"
password = "cubeice45"
password1 = "tomcat5"
password2 = "flyer42"
function menu()
    term.clear()
    term.setCursorPos(1,1)
    print("Control Panel V1.0")
    print("1: Toggle Dungeon")
    print("2: Toggle Quarry")
    print("3: Toggle Logo")
    print("4: Status Report")
    print("5: Log Out")
    print("What Would You Like To Do?")
    input = read()
    if input == "1" then
        c = colors.combine(c, colors.blue)
        rs.setBundledOutput("back", c )
        os.sleep(1)
        c = colors.subtract(c, colors.blue)
        rs.setBundledOutput("back", c)
        return menu()
    elseif input == "2" then
	    print("Under Construction")
	    os.sleep(2)
	    return menu()
    elseif input == "3" then
        d = colors.combine(d, colors.yellow)
        rs.setBundledOutput("back", d )
        os.sleep(1)
        d = colors.subtract(d, colors.yellow)
        rs.setBundledOutput("back", d)
        return menu()
    elseif input == "4" then
	    c = colors.combine(c, colors.blue)
	    if redstone.testBundledInput("left", c) == true then
		    logostatus = "Off"
        end
    elseif input == "5" then
	    print("Thank You for Using The Control Panel")
	    os.sleep(2)
	    os.reboot()
    else
        logostatus = "On"
        if redstone.testBundledInput("left", d) == true then
            dungeonstatus = "Off"
        else
            dungeonstatus = "On"
            term.clear()
            term.setCursorPos(1,1)
            print("Dungeon is "..dungeonstatus)
            print("Quarry is UNKNOWN")
            print("Logo is "..logostatus)
            os.sleep(4)
            return menu()
        end
    end
    shell.run("monitor", "top", "face")
    term.clear()
    term.setCursorPos(1,1)
    print("FactoryOS V2.0")
    print("Choose A User:")
    usercheck = read()
    if usercheck == user or usercheck == user1 or usercheck == user2 then
	    term.clear()
	    term.setCursorPos(1,1)
	    print(usercheck.."'s Password:")
	    passcheck = read("*")
	    if passcheck == password or passcheck == password1 or passcheck == password2 then
		    term.clear()
		    term.setCursorPos(1,1)
		    menu()
	    else
		    print("Invalid Password")
            sleep(2)
		    os.reboot()
	    end
    else
	    print("Invalid User")
        sleep(2)
        os.reboot()
    end
end

menu()

And where have you defined c and d?