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

Exit Program Useing Monitor Touch

Started by bluefoxy, 10 October 2013 - 10:27 PM
bluefoxy #1
Posted 11 October 2013 - 12:27 AM
so i have a simle issue im not understanding here,
i have this script its working just fine BUT, wwhen i touch the shot on the screen to exit the program and return to the shell nothing happens. but if i change the shell.exit() to and thing like print("this one works") it will show it on the computer but not the screen.
so any idea what i can do to get the button to exit the program and go back to shell when clicked?

Incase your wondering yes its a tut. program from youtube (im trying to learn)

mouseWidth = 0
mouseHeight = 0
monitor = peripheral.wrap("left")
monitor.clear()
monitor.setCursorPos(1,1)
w,h=monitor.getSize()
print(w)
print(h)

monitor.setBackgroundColour((colours.lime))
monitor.setCursorPos(2,2)
monitor.write(" ON  ")
monitor.setCursorPos(2,4)
monitor.write(" OFF ")
monitor.setBackgroundColour((colours.black))
function checkClickPosition()
  if mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 2 then
    -- button one clicked
    shell.run("todo")
    -- turns redstone connected to the right on
  elseif mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 4 then
    -- button two clicked
    shell.exit()
    -- turns redstone connected to the left off
  end -- ends the if loop
end -- ends the function
repeat
  event,p1,p2,p3 = os.pullEvent()
   if event=="monitor_touch" then
	 mouseWidth = p2 -- sets mouseWidth
	 mouseHeight = p3 -- and mouseHeight
	 checkClickPosition() -- this runs our function
	
   end

until event=="char" and p1==("x")
immibis #2
Posted 11 October 2013 - 02:00 AM
Instead of "shell.exit()", use "return" or "error()"
bluefoxy #3
Posted 11 October 2013 - 01:19 PM
that didnt work, i did try both
and well nothng happened XD
Bomb Bloke #4
Posted 11 October 2013 - 06:30 PM
"return" would only end the click-checking function, but "error()" should definitely work.

Though, the comments make it look like your actual goal is redstone manipulation - exiting the script won't disable any redstone signals the computer is sending, only make it impossible to use the screen until you start it again! You may want something like this instead:

  if mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 2 then
	-- button one clicked
	redstone.setOutput("right", true) -- turns redstone connected to the right on
  elseif mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 4 then
	-- button two clicked
	redstone.setOutput("right", false) -- turns redstone connected to the right off
  end -- ends the if block