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

Menu code errors

Started by Ultionisus, 02 April 2013 - 11:56 AM
Ultionisus #1
Posted 02 April 2013 - 01:56 PM
Hello all, i'm relatively new to computercraft and have encountered the following error while trying to construct a program.
I'm not certain what in the code caused the error, but I think it might be due to the program not being able to access the menus.
I'll explain what it is I wanted the program to do first then i'll post the code up which hopefully someone could correct for me.
I wanted a menu system which could access two different sub menus with their own gui. I've used the gui part of the code before and tried to combine it with a menu program i'd found, somewhat disastrously xD anyway here's the code I made apologies it's so long.

The error is it loops the message ''No Such Program''


term.setTextColor(colors.green)
while x ~= "exit" do
print("-------------------------------")
print("Titan Manifold Control System:")
print("Alpha to select Titan Activation Protocols.")
print("Omega to select Titan Adminstrative Protocols.")
print("Type exit to go back to previous menu.")

write(" Enter a command now my princeps.")

print("-------------------------------")

x = io.read()

if x == "Alpha" then


  while y ~= "exit" do
  y = io.read()

   if y == "on" then

   term.clear()
			term.setCursorPos(1,1)
   term.setTextColor(colors.green)
   print"  ---------------------------------------------- "
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print"  ---------------------------------------------- "
			term.setCursorPos(19,3)
			print"Current Status:"
			if colors.test(redstone.getBundledOutput("back"), colors.blue) == false then
			Reactor = "Off"
			else
			Reactor = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.black) == false then
			Containment = "Off"
			else
			Containment = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.yellow) == false then
			Flood Protocol = "Off"
			else
			Flood Protocol = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.gray) == false then
			Illumination = "Off"
			else
			Illumination = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.red) == false then
			Reactor Access = "Off"
			else
			Reactor Access = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.orange) == false then
			HazMat locker = "Off"
			else
			HazMat locker = "On"
			end
			term.setCursorPos(5,5)
			write("1 - Reactor activation: ")
			write(Reactor)
			term.setCursorPos(28,5)
			write("2 - Reactor Containment:   ")
			write(Containment)
			term.setCursorPos(5,7)
			write("3 - Flood Protocol:  ")
			write(Flood)
			term.setCursorPos(28,7)
			write("4 - Illumination:   ")
			write(Illumination)
			term.setCursorPos(5,9)
			write("5 - Reactor Access:  ")
			write(Reactor Access)
			term.setCursorPos(28,9)
			write("6 - HazMat locker:	 ")
			write(HazMat locker)
			term.setCursorPos(3,12)
			write("Select a Service From The List Above And Enter")
			term.setCursorPos(7,13)
			write("Its ID Below Or leave Blank To Log Out")
			term.setCursorPos(21,15)
			write("Enter ID: ")
			sleep(1)
			input = read()
			term.clear()
			term.setCursorPos(1,1)
   term.setTextColor(colors.green)
			print"  ---------------------------------------------- "
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print"  ---------------------------------------------- "
			term.setCursorPos(15,9)
			if input == "1" then
			if Reactor == "On" then
			print"Reactor Initialised"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.blue))
			else
			print"Reactor Deactivated"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.blue))
			end
			elseif input == "2" then
			if Reactor Containment == "On" then
			print" Reactor Containment Deactivated"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.black))
			else
			print" Reactor Containment Activated"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.black))
			end
			elseif input == "3" then
			if Flood Protocol == "On" then
			print"Flood Protocol Deactive"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.yellow))
			else
			print"Flood Protocol Active"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.yellow))
			end
			elseif input == "4" then
			if Titan Illumination == "On" then
			print" Titan Illumination deactivated"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.gray))
			else
			print" Titan Illumination Activated"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.gray))
			end
			elseif input == "5" then
			if Reactor Access == "On" then
			print"Reactor Access Withdrawn"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.red))
			else
			print"Reactor Access Granted"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.red))
			end
			elseif input == "6" then
			if HazMat locker == "On" then
			print"  HazMat locker locked"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.orange))
			else
			print"  HazMat locker unlocked"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.orange))
			end
			else
			   end -- if y = on/off

		 end -- while y
			end -- if Alpha
if x == "Omega" then



  while u ~= "exit" do
			  u=io.read()
   if y == "on" then

   term.clear()
			term.setCursorPos(1,1)
   term.setTextColor(colors.green)
   print"  ---------------------------------------------- "
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print"  ---------------------------------------------- "
			term.setCursorPos(19,3)
			print"Current Status:"
			if colors.test(redstone.getBundledOutput("back"), colors.blue) == false then
			Head blast doors. = "Off"
			else
			Head blast doors. = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.black) == false then
			Carapace access hatches. = "Off"
			else
			Carapace access hatches. = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.yellow) == false then
			Carapace boarding hatch. = "Off"
			else
			Carapace boarding hatch. = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.gray) == false then
			Thoracic Elevator. = "Off"
			else
			Thoracic Elevator. = "On"
			end
			if colors.test(redstone.getBundledOutput("back"), colors.red) == false then
			Point Defence system. = "Off"
			else
			Point Defence system. = "On"
			end
			term.setCursorPos(5,5)
			write("1 - Head blast doors.: ")
			write(Head blast doors.)
			term.setCursorPos(28,5)
			write("2 - Carapace access hatches.:   ")
			write(Carapace access hatches.)
			term.setCursorPos(5,7)
			write("3 - Carapace boarding hatch.:  ")
			write(Carapace boarding hatch.)
			term.setCursorPos(28,7)
			write("4 - Thoracic Elevator.:   ")
			write(Thoracic Elevator.)
			term.setCursorPos(5,9)
			write("5 - Point Defence system.:  ")
			write(Point Defence system.)
			term.setCursorPos(3,12)
			write("Select a Service From The List Above And Enter")
			term.setCursorPos(7,13)
			write("Its ID Below Or leave Blank To Log Out")
			term.setCursorPos(21,15)
			write("Enter ID: ")
			sleep(1)
			input = read()
			term.clear()
			term.setCursorPos(1,1)
   term.setTextColor(colors.green)
			print"  ---------------------------------------------- "
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print" |											  |"
			print"  ---------------------------------------------- "
			term.setCursorPos(15,9)
			if input == "1" then
			if Head blast doors == "On" then
			print"Head blast doors extended"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.blue))
			else
			print"Head blast doors Retracted"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.blue))
			end
			elseif input == "2" then
			if Carapace access hatches. == "On" then
			print" Carapace access hatches. Sealed"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.black))
			else
			print" Carapace access hatches. Open"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.black))
			end
			elseif input == "3" then
			if Carapace boarding hatch. == "On" then
			print"Carapace boarding hatch. Retracted"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.yellow))
			else
			print"Carapace boarding hatch Sealed."
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.yellow))
			end
			elseif input == "4" then
			if Thoracic Elevator. == "On" then
			print" Thoracic Elevator. Direction Upper level"
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.gray))
			else
			print" Thoracic Elevator. Direction Lower level"
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.gray))
			end
			elseif input == "5" then
			if Point Defence system. == "On" then
			print"Point Defence system Deactivated."
			rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.red))
			else
			print"Point Defence system. Active."
			rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.red))
			end
			else
   end -- if u = on/off

  end -- while u

end -- if em

end -- while z
Yes it's a computer control system for the functions in my titan (40k reference).
Thankyou for your help in advance and I apologies for the mess that is my code and it's length.
P.s it appears it isn't displaying the GUI screen properly in the paste above, whilst it does in notepad.
Ultionisus #2
Posted 03 April 2013 - 05:19 PM
I apologies for the length of this post and code and for bumping my own topic but i'd really appreciate some help with this, it's one of the final things i need to do to finish my project
Bubba #3
Posted 03 April 2013 - 05:43 PM
I think it's perfectly reasonable to bump after a day or two in Ask a Pro :)/>

The first issue that sticks out to me is that you have variables with spaces in them. You can't do that in lua. Try changing them to things like "HazMat_Locker" (underscore characters work fine: just no spaces). Also, you should not have periods in a variable name.
Brandhout #4
Posted 03 April 2013 - 05:54 PM
It's things like this you cannot do:

Flood Protocol = "Off"
You cannot use spaces in variable names, instead use a _ or leave the space out:

FloodProtocol = "Off"

I'm also not sure if dots are allowed in variable names. Just better leave em out.

Edit: Seems im too late :-(
Bubba #5
Posted 03 April 2013 - 05:55 PM
It's things like this you cannot do:

Flood Protocol = "Off"
You cannot use spaces in variable names, instead use a _ or leave the space out:

FloodProtocol = "Off"

I'm also not sure if dots are allowed in variable names. Just better leave em out.

They are not [allowed]. Periods usually signify that you are trying to access a value from a table and will error if used on a non-table.

BTW, I fixed all of the variables with spaces and added a couple of ends as well. I'm not sure if it fixed everything, but it will at least run now. Give this a shot: Link
Spoiler

term.setTextColor(colors.green)
while x ~= "exit" do
print("-------------------------------")
print("Titan Manifold Control System:")
print("Alpha to select Titan Activation Protocols.")
print("Omega to select Titan Adminstrative Protocols.")
print("Type exit to go back to previous menu.")

write(" Enter a command now my princeps.")

print("-------------------------------")

x = io.read()

if x == "Alpha" then


  while y ~= "exit" do
  y = io.read()

   if y == "on" then

   term.clear()
						term.setCursorPos(1,1)
   term.setTextColor(colors.green)
   print"  ---------------------------------------------- "
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print"  ---------------------------------------------- "
						term.setCursorPos(19,3)
						print"Current Status:"
						if colors.test(redstone.getBundledOutput("back"), colors.blue) == false then
						Reactor = "Off"
						else
						Reactor = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.black) == false then
						Containment = "Off"
						else
						Containment = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.yellow) == false then
						Flood_Protocol = "Off"
						else
						Flood_Protocol = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.gray) == false then
						Illumination = "Off"
						else
						Illumination = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.red) == false then
						Reactor_Access = "Off"
						else
						Reactor_Access = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.orange) == false then
						HazMat_locker = "Off"
						else
						HazMat_locker = "On"
						end
						term.setCursorPos(5,5)
						write("1 - Reactor activation: ")
						write(Reactor)
						term.setCursorPos(28,5)
						write("2 - Reactor_Containment:   ")
						write(Containment)
						term.setCursorPos(5,7)
						write("3 - Flood_Protocol:  ")
						write(Flood)
						term.setCursorPos(28,7)
						write("4 - Illumination:   ")
						write(Illumination)
						term.setCursorPos(5,9)
						write("5 - Reactor_Access:  ")
						write(Reactor_Access)
						term.setCursorPos(28,9)
						write("6 - HazMat_locker:		")
						write(HazMat_locker)
						term.setCursorPos(3,12)
						write("Select a Service From The List Above And Enter")
						term.setCursorPos(7,13)
						write("Its ID Below Or leave Blank To Log Out")
						term.setCursorPos(21,15)
						write("Enter ID: ")
						sleep(1)
						input = read()
						term.clear()
						term.setCursorPos(1,1)
   term.setTextColor(colors.green)
						print"  ---------------------------------------------- "
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print"  ---------------------------------------------- "
						term.setCursorPos(15,9)
						if input == "1" then
						if Reactor == "On" then
						print"Reactor Initialised"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.blue))
						else
						print"Reactor Deactivated"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.blue))
						end
						elseif input == "2" then
						if Reactor_Containment == "On" then
						print" Reactor_Containment Deactivated"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.black))
						else
						print" Reactor_Containment Activated"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.black))
						end
						elseif input == "3" then
						if Flood_Protocol == "On" then
						print"Flood_Protocol Deactive"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.yellow))
						else
						print"Flood_Protocol Active"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.yellow))
						end
						elseif input == "4" then
						if Titan_Illumination == "On" then
						print" Titan_Illumination deactivated"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.gray))
						else
						print" Titan_Illumination Activated"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.gray))
						end
						elseif input == "5" then
						if Reactor_Access == "On" then
						print"Reactor_Access Withdrawn"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.red))
						else
						print"Reactor_Access Granted"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.red))
						end
						elseif input == "6" then
						if HazMat_locker == "On" then
						print"  HazMat_locker locked"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.orange))
						else
						print"  HazMat_locker unlocked"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.orange))
						end
						else
						   end -- if y = on/off

				 end -- while y
						end -- if Alpha
if x == "Omega" then



  while u ~= "exit" do
						  u=io.read()
   if y == "on" then

   term.clear()
						term.setCursorPos(1,1)
   term.setTextColor(colors.green)
   print"  ---------------------------------------------- "
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print"  ---------------------------------------------- "
						term.setCursorPos(19,3)
						print"Current Status:"
						if colors.test(redstone.getBundledOutput("back"), colors.blue) == false then
						Head_blast_doors = "Off"
						else
						Head_blast_doors = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.black) == false then
						Carapace_access_hatches = "Off"
						else
						Carapace_access_hatches = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.yellow) == false then
						Carapace_boarding_hatch = "Off"
						else
						Carapace_boarding_hatch = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.gray) == false then
						Thoracic_Elevator = "Off"
						else
						Thoracic_Elevator = "On"
						end
						if colors.test(redstone.getBundledOutput("back"), colors.red) == false then
						Point_Defence_system = "Off"
						else
						Point_Defence_system = "On"
						end
						term.setCursorPos(5,5)
						write("1 - Head_blast_doors: ")
						write(Head_blast_doors)
						term.setCursorPos(28,5)
						write("2 - Carapace_access_hatches:   ")
						write(Carapace_access_hatches)
						term.setCursorPos(5,7)
						write("3 - Carapace_boarding_hatch:  ")
						write(Carapace_boarding_hatch)
						term.setCursorPos(28,7)
						write("4 - Thoracic_Elevator:   ")
						write(Thoracic_Elevator)
						term.setCursorPos(5,9)
						write("5 - Point_Defence_system:  ")
						write(Point_Defence_system)
						term.setCursorPos(3,12)
						write("Select a Service From The List Above And Enter")
						term.setCursorPos(7,13)
						write("Its ID Below Or leave Blank To Log Out")
						term.setCursorPos(21,15)
						write("Enter ID: ")
						sleep(1)
						input = read()
						term.clear()
						term.setCursorPos(1,1)
   term.setTextColor(colors.green)
						print"  ---------------------------------------------- "
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print" |																						  |"
						print"  ---------------------------------------------- "
						term.setCursorPos(15,9)
						if input == "1" then
						if Head_blast_doors == "On" then
						print"Head_doors_extended"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.blue))
						else
						print"Head_doors_Retracted"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.blue))
						end
						elseif input == "2" then
						if Carapace_access_hatches == "On" then
						print" Carapace_access_hatches Sealed"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.black))
						else
						print" Carapace_access_hatches Open"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.black))
						end
						elseif input == "3" then
						if Carapace_boarding_hatch == "On" then
						print"Carapace_boarding_hatch Retracted"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.yellow))
						else
						print"Carapace boarding hatch Sealed."
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.yellow))
						end
						elseif input == "4" then
						if Thoracic_Elevator == "On" then
						print" Thoracic_Elevator Direction Upper level"
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.gray))
						else
						print" Thoracic_Elevator Direction Lower level"
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.gray))
						end
						elseif input == "5" then
						if Point_Defence_system == "On" then
						print"Point Defence system Deactivated."
						rs.setBundledOutput("back", colors.subtract( rs.getBundledOutput( "back" ), colors.red))
						else
						print"Point_Defence_system Active."
						rs.setBundledOutput("back", colors.combine( rs.getBundledOutput( "back" ), colors.red))
						end
						else
   end -- if u = on/off

  end -- while u

end -- if em

end -- while z
end

end