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

My control panel stopped working:(

Started by Lasere123456, 26 July 2012 - 08:50 PM
Lasere123456 #1
Posted 26 July 2012 - 10:50 PM
I have no clue what i did, but i must have enter something that the program did not like.
because it worked perfectly until i did a to long editing session.

my program is a control panel used to control 5 different systems.
and it works just as i want it to, until i return to the main control panel after using a sub-page
if i try to enter the same sub page i have used before it just ignores my command, but it still works for my other sub pages.


local function AddOutput(sSide, ...)
  local c = colors.combine(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end
local function RemoveOutput(sSide, ...)
  local c = colors.subtract(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end
while x1 ~= "consol" do
	term.clear()
print("-------------------------------------------")
print("----------------Main menu:-----------------")
print("-------------------------------------------")
print("Options:")
print("-------------------------------------------")
print("Querry")
   if rs.testBundledInput("back", colors.lime ) == true then
   print("Status: Online")
   else
   print("Status: Offline")
   end
print("OilPump")
   if rs.testBundledInput("back", colors.pink ) == true then
   print("Status: Online")
   else
   print("Status: Offline")
   end
print("Cooling")
   if rs.testBundledInput("back", colors.gray ) == true then
   print("Status: Online")
   else
   print("Status: Offline")
   end
print("Security")
   if rs.testBundledInput("back", colors.lightGray ) == true then
   print("Status: Online")
   else
   print("Status: Offline")
   end
print("MobFarm")
   if rs.testBundledInput("back", colors.cyan ) == true then
   print("Status: Online")
   else
   print("Status: Offline")
   end
print("Consol")
print("-------------------------------------------")
write("Enter menu command: ")

x1 = io.read()
if x1 == "querry" then


  while x2 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("----------------Querry menu:---------------")
   print("-------------------------------------------")
	if rs.testBundledInput("back", colors.lime ) == true then
	print("Status: Online")
	else
	print("Status: Offline")
	end
   print("To turn Querry on, type on.")
   print("To turn Querry off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter querry command: ")

   x2 = io.read()

   if x2 == "on" then

	AddOutput("back", colors.white )
	term.clear()
	print("------------------------------------------")
	print("The querry is now on.")
	print("------------------------------------------")
	sleep(1)

	elseif x2 == "off" then
	RemoveOutput("back", colors.white )
	print("------------------------------------------")
	print("The querry is now off.")
	print("------------------------------------------")

   end -- if x2 = on/off
  end -- while x2

end -- if Querry

if x1 == "oilpump" then
  while x3 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Oilpump menu:---------------")
   print("-------------------------------------------")
	if rs.testBundledInput("back", colors.pink ) == true then
	print("Status: Online")
	else
	print("Status: Offline")
	end
   print("To turn on the oilpumps, type on.")
   print("To turn off the oilpumps, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter oilpump command: ")

   x3 = io.read()
   if x3 == "on" then

	AddOutput("back", colors.orange )
	term.clear()
	print("------------------------------------------")
	print("The oilpumps are now on.")
	print("------------------------------------------")
	sleep(1)

   elseif x3 == "off" then
	RemoveOutput("back", colors.orange )
	term.clear()
	print("------------------------------------------")
	print("The oilpumps are now off.")
	print("------------------------------------------")
	sleep(1)

   end -- if x3 = on/off

  end -- while x3

end -- if oilpumps

  if x1 == "cooling" then

  while x4 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Cooling menu:---------------")
   print("-------------------------------------------")
	if rs.testBundledInput("back", colors.gray ) == true then
	print("Status: Online")
	else
	print("Status: Offline")
	end
   print("To turn on the Cooling, type on.")
			print("To turn off the Cooling, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter Cooling command: ")

   x4 = io.read()

   if x4 == "on" then

	AddOutput("back", colors.magenta )
	term.clear()
	print("------------------------------------------")
	print("The cooling is now on.")
	print("------------------------------------------")
	sleep(1)

   elseif x4 == "off" then
	RemoveOutput("back", colors.magenta )
	term.clear()
	print("------------------------------------------")
	print("The Cooling is now off.")
	print("------------------------------------------")
	sleep(1)

   end -- if x4 = on/off

  end -- while x4

end -- if Cooling

  if x1 == "security" then

  while x5 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Security menu:--------------")
   print("-------------------------------------------")
	if rs.testBundledInput("back", colors.lightGray ) == true then
	print("Status: Online")
	else
	print("Status: Offline")
	end
   print("To turn security on, type on.")
   print("To turn security off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter security command: ")

   x5 = io.read()

   if x5 == "on" then

	AddOutput("back", colors.lightBlue )
	term.clear()
	print("------------------------------------------")
	print("The security is now on.")
	print("------------------------------------------")
	sleep(1)

	elseif x5 == "off" then
	RemoveOutput("back", colors.lightBlue )
	term.clear()
	print("------------------------------------------")
	print("The security is now off.")
		print("------------------------------------------")
	sleep(1)

   end -- if x5 = on/off

  end -- while x5

end -- if security

  if x1 == "mobfarm" then

  while x6 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------MobFarm menu:---------------")
   print("-------------------------------------------")
	if rs.testBundledInput("back", colors.cyan ) == true then
	print("Status: Online")
	else
	print("Status: Offline")
	end
   print("To turn on the Mob farm, type on.")
   print("To turn off the Mob farm, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter command: ")

   x6 = io.read()

   if x6 == "on" then

	AddOutput("back", colors.yellow )
	term.clear()
	print("------------------------------------------")
	print("The Mob farm is now on.")
	print("------------------------------------------")
	sleep(1)

   elseif x6 == "off" then
	RemoveOutput("back", colors.yellow )
	term.clear()
	print("------------------------------------------")
	print("The Mob farm is now off.")
	print("------------------------------------------")
	sleep(1)
   end -- if x6 = on/off

  end -- while x6

end -- if modfarm

end -- Main end
brett122798 #2
Posted 26 July 2012 - 11:09 PM
Can't really tell you what the problem is cause it looks quite complex but if nobody can help you with that, you may want to consider organizing everything into functions.
Lasere123456 #3
Posted 27 July 2012 - 12:22 AM
its only the fist lines that are complex the rest is just the same stuff going over and over again
Lasere123456 #4
Posted 27 July 2012 - 10:08 AM
common guys i really need help on this:(
i tried to make some comments on the code, but at least from my perspective it so easy to read.
but if someone need help understanding a piece of the code post it her.
BigSHinyToys #5
Posted 27 July 2012 - 10:42 AM
I will look into it. give me a munite
Lasere123456 #6
Posted 27 July 2012 - 11:03 AM
thx
BigSHinyToys #7
Posted 27 July 2012 - 11:20 AM
I have not tesetd all options But i think i have the probblem figured out. your x1 , x2 ect… are never reset from "back" so when called again the loop never runs as it is "back" putting in the x1 = nil should fix it.

try this out
Spoiler

local function AddOutput(sSide, ...)
local c = colors.combine(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
local function RemoveOutput(sSide, ...)
local c = colors.subtract(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
while x1 ~= "consol" do
term.clear()
print("-------------------------------------------")
print("----------------Main menu:-----------------")
print("-------------------------------------------")
print("Options:")
print("-------------------------------------------")
print("Querry")
if rs.testBundledInput("back", colors.lime ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("OilPump")
if rs.testBundledInput("back", colors.pink ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Cooling")
if rs.testBundledInput("back", colors.gray ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Security")
if rs.testBundledInput("back", colors.lightGray ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("MobFarm")
if rs.testBundledInput("back", colors.cyan ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Consol")
print("-------------------------------------------")
write("Enter menu command: ")
x1 = io.read()
x2 = nil -- these reset the system
x3 = nil
x4 = nil
x5 = nil
x6 = nil
if x1 == "querry" then
  while x2 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("----------------Querry menu:---------------")
   print("-------------------------------------------")
   if rs.testBundledInput("back", colors.lime ) == true then
    print("Status: Online")
   else
    print("Status: Offline")
   end
   print("To turn Querry on, type on.")
   print("To turn Querry off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter querry command: ")
   x2 = io.read()
   if x2 == "on" then
    AddOutput("back", colors.white )
    term.clear()
    print("------------------------------------------")
    print("The querry is now on.")
    print("------------------------------------------")
    sleep(1)
   elseif x2 == "off" then
    RemoveOutput("back", colors.white )
    print("------------------------------------------")
    print("The querry is now off.")
    print("------------------------------------------")
   end -- if x2 = on/off
  end -- while x2
end -- if Querry
if x1 == "oilpump" then
  while x3 ~= "back" do
  term.clear()
  print("-------------------------------------------")
  print("---------------Oilpump menu:---------------")
  print("-------------------------------------------")
  if rs.testBundledInput("back", colors.pink ) == true then
   print("Status: Online")
  else
   print("Status: Offline")
  end
  print("To turn on the oilpumps, type on.")
  print("To turn off the oilpumps, type off.")
  print("To get back to the main menu, type back.")
  print("-------------------------------------------")
  write("Enter oilpump command: ")
  x3 = io.read()
  if x3 == "on" then
   AddOutput("back", colors.orange )
   term.clear()
   print("------------------------------------------")
   print("The oilpumps are now on.")
   print("------------------------------------------")
   sleep(1)
elseif x3 == "off" then
  RemoveOutput("back", colors.orange )
  term.clear()
  print("------------------------------------------")
  print("The oilpumps are now off.")
  print("------------------------------------------")
  sleep(1)
end -- if x3 = on/off
end -- while x3
end -- if oilpumps
  if x1 == "cooling" then
  while x4 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Cooling menu:---------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.gray ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn on the Cooling, type on.")
					    print("To turn off the Cooling, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter Cooling command: ")
   x4 = io.read()
   if x4 == "on" then
	    AddOutput("back", colors.magenta )
	    term.clear()
	    print("------------------------------------------")
	    print("The cooling is now on.")
	    print("------------------------------------------")
	    sleep(1)
   elseif x4 == "off" then
	    RemoveOutput("back", colors.magenta )
	    term.clear()
	    print("------------------------------------------")
	    print("The Cooling is now off.")
	    print("------------------------------------------")
	    sleep(1)
   end -- if x4 = on/off
  end -- while x4
end -- if Cooling
  if x1 == "security" then
  while x5 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Security menu:--------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.lightGray ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn security on, type on.")
   print("To turn security off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter security command: ")
   x5 = io.read()
   if x5 == "on" then
	    AddOutput("back", colors.lightBlue )
	    term.clear()
	    print("------------------------------------------")
	    print("The security is now on.")
	    print("------------------------------------------")
	    sleep(1)
	    elseif x5 == "off" then
	    RemoveOutput("back", colors.lightBlue )
	    term.clear()
	    print("------------------------------------------")
	    print("The security is now off.")
			    print("------------------------------------------")
	    sleep(1)
   end -- if x5 = on/off
  end -- while x5
end -- if security
  if x1 == "mobfarm" then
  while x6 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------MobFarm menu:---------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.cyan ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn on the Mob farm, type on.")
   print("To turn off the Mob farm, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter command: ")
   x6 = io.read()
   if x6 == "on" then
	    AddOutput("back", colors.yellow )
	    term.clear()
	    print("------------------------------------------")
	    print("The Mob farm is now on.")
	    print("------------------------------------------")
	    sleep(1)
   elseif x6 == "off" then
	    RemoveOutput("back", colors.yellow )
	    term.clear()
	    print("------------------------------------------")
	    print("The Mob farm is now off.")
	    print("------------------------------------------")
	    sleep(1)
   end -- if x6 = on/off
  end -- while x6
end -- if modfarm
end -- Main end
Luanub #8
Posted 27 July 2012 - 11:32 AM
I would consider doing what brett122798 recommended.

The issue is that say you go into querry, then type back to go back to the main menu. This changed the x2 var to "back" so when you enter querry again you while loop see's x2 == "back" and does not run anything in the loop. There are much better ways to get the desired functionality out of the script.

Also I would combine all of you're if x1 == statements into one. Since you are only entered 1 input its better to only check that 1 input once.

Bah ninja'd to much typing lol :)/>/>

I would still consider changing the code, loops inside of loops inside of loops can cause issues.
Edited on 27 July 2012 - 09:36 AM
BigSHinyToys #9
Posted 27 July 2012 - 11:41 AM
I would recommend the same as the above refactoring your code to use function in the long run will work out better
Lasere123456 #10
Posted 27 July 2012 - 12:06 PM
THANK U BigShinyToys!!

two more question tho…
is there a way to make it not reset in ssp?
and
will it also reset if the chunk is unloaded in smp?

(its made in ssp, but inted to be used in smp.
BigSHinyToys #11
Posted 27 July 2012 - 12:18 PM
THANK U BigShinyToys!!

two more question tho…
is there a way to make it not reset in ssp?
and
will it also reset if the chunk is unloaded in smp?

(its made in ssp, but inted to be used in smp.
Computers will always restart if they were on and the world or chunk reloads this is just a limitation you will have to live with.

There are work around's You can store the output number in a file and when the computer restarts have it set the bundle to that number.

I could make a simple function to load and save this variable if you would like
Lasere123456 #12
Posted 27 July 2012 - 12:35 PM
That would be great, i am fairly new to programming, and have no idea on how to do it myself.
(the 2 functions in there start is written by MysticT, because i had no clue on how to write functions myself…)
BigSHinyToys #13
Posted 27 July 2012 - 01:47 PM
That would be great, i am fairly new to programming, and have no idea on how to do it myself.
(the 2 functions in there start is written by MysticT, because i had no clue on how to write functions myself…)
file access can be a pain at times But this should work

Spoiler

-- this loads the varible
local iConfig = nil
local sName = "config"
local sBundelSide = "back"
local function save(sInput)
local file = io.open(sName,"w")
file:write(tostring(sInput))
file:close()
end
local function AddOutput(sSide, ...)
local c = colors.combine(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
save(c)
end
local function RemoveOutput(sSide, ...)
local c = colors.subtract(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
save(c)
end

if fs.exists(sName) then
print("Loading config")
file = io.open(sName,"r")
iConfig = tonumber(file:read())
print(iConfig)
file:close()
print("Config loaded")
else
print("No config")
iConfig = 0
end
print(iConfig)
rs.setBundledOutput(sBundelSide,iConfig) -- this sets it as the output
sleep(1) -- gives time for output to change
-- end
local x1 = nil -- resets x1
while x1 ~= "consol" do
save(rs.getBundledOutput(sBundelSide)) -- saves eveery tiem you return to main menu
term.clear()
print("-------------------------------------------")
print("----------------Main menu:-----------------")
print("-------------------------------------------")
print("Options:")
print("-------------------------------------------")
print("Querry")
if rs.testBundledInput("back", colors.lime ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("OilPump")
if rs.testBundledInput("back", colors.pink ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Cooling")
if rs.testBundledInput("back", colors.gray ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Security")
if rs.testBundledInput("back", colors.lightGray ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("MobFarm")
if rs.testBundledInput("back", colors.cyan ) == true then
  print("Status: Online")
else
  print("Status: Offline")
end
print("Consol")
print("-------------------------------------------")
write("Enter menu command: ")
x1 = io.read()
x2 = nil -- these reset the system
x3 = nil
x4 = nil
x5 = nil
x6 = nil
if x1 == "querry" then
  while x2 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("----------------Querry menu:---------------")
   print("-------------------------------------------")
   if rs.testBundledInput("back", colors.lime ) == true then
    print("Status: Online")
   else
    print("Status: Offline")
   end
   print("To turn Querry on, type on.")
   print("To turn Querry off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter querry command: ")
   x2 = io.read()
   if x2 == "on" then
    AddOutput("back", colors.white )
    term.clear()
    print("------------------------------------------")
    print("The querry is now on.")
    print("------------------------------------------")
    sleep(1)
   elseif x2 == "off" then
  
    RemoveOutput("back", colors.white )
    print("------------------------------------------")
    print("The querry is now off.")
    print("------------------------------------------")
    sleep(1)
   end -- if x2 = on/off
  end -- while x2
end -- if Querry
if x1 == "oilpump" then
  while x3 ~= "back" do
  term.clear()
  print("-------------------------------------------")
  print("---------------Oilpump menu:---------------")
  print("-------------------------------------------")
  if rs.testBundledInput("back", colors.pink ) == true then
   print("Status: Online")
  else
   print("Status: Offline")
  end
  print("To turn on the oilpumps, type on.")
  print("To turn off the oilpumps, type off.")
  print("To get back to the main menu, type back.")
  print("-------------------------------------------")
  write("Enter oilpump command: ")
  x3 = io.read()
  if x3 == "on" then
   AddOutput("back", colors.orange )
   term.clear()
   print("------------------------------------------")
   print("The oilpumps are now on.")
   print("------------------------------------------")
   sleep(1)
elseif x3 == "off" then
  RemoveOutput("back", colors.orange )
  term.clear()
  print("------------------------------------------")
  print("The oilpumps are now off.")
  print("------------------------------------------")
  sleep(1)
end -- if x3 = on/off
end -- while x3
end -- if oilpumps
  if x1 == "cooling" then
  while x4 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Cooling menu:---------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.gray ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn on the Cooling, type on.")
					    print("To turn off the Cooling, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter Cooling command: ")
   x4 = io.read()
   if x4 == "on" then
	    AddOutput("back", colors.magenta )
	    term.clear()
	    print("------------------------------------------")
	    print("The cooling is now on.")
	    print("------------------------------------------")
	    sleep(1)
   elseif x4 == "off" then
	    RemoveOutput("back", colors.magenta )
	    term.clear()
	    print("------------------------------------------")
	    print("The Cooling is now off.")
	    print("------------------------------------------")
	    sleep(1)
   end -- if x4 = on/off
  end -- while x4
end -- if Cooling
  if x1 == "security" then
  while x5 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------Security menu:--------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.lightGray ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn security on, type on.")
   print("To turn security off, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter security command: ")
   x5 = io.read()
   if x5 == "on" then
	    AddOutput("back", colors.lightBlue )
	    term.clear()
	    print("------------------------------------------")
	    print("The security is now on.")
	    print("------------------------------------------")
	    sleep(1)
	    elseif x5 == "off" then
	    RemoveOutput("back", colors.lightBlue )
	    term.clear()
	    print("------------------------------------------")
	    print("The security is now off.")
			    print("------------------------------------------")
	    sleep(1)
   end -- if x5 = on/off
  end -- while x5
end -- if security
  if x1 == "mobfarm" then
  while x6 ~= "back" do
   term.clear()
   print("-------------------------------------------")
   print("---------------MobFarm menu:---------------")
   print("-------------------------------------------")
	    if rs.testBundledInput("back", colors.cyan ) == true then
	    print("Status: Online")
	    else
	    print("Status: Offline")
	    end
   print("To turn on the Mob farm, type on.")
   print("To turn off the Mob farm, type off.")
   print("To get back to the main menu, type back.")
   print("-------------------------------------------")
   write("Enter command: ")
   x6 = io.read()
   if x6 == "on" then
	    AddOutput("back", colors.yellow )
	    term.clear()
	    print("------------------------------------------")
	    print("The Mob farm is now on.")
	    print("------------------------------------------")
	    sleep(1)
   elseif x6 == "off" then
	    RemoveOutput("back", colors.yellow )
	    term.clear()
	    print("------------------------------------------")
	    print("The Mob farm is now off.")
	    print("------------------------------------------")
	    sleep(1)
   end -- if x6 = on/off
  end -- while x6
end -- if modfarm
end -- Main end

If there are any other problems just post and i will see what i can do I have to go right now so don't expect anything quickly is all