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

Programm wont run with a button event

Started by Bizzlike, 26 March 2016 - 09:04 AM
Bizzlike #1
Posted 26 March 2016 - 10:04 AM
Hey I want to run 2 diffrent programms with a programm when i click an the X on the screen but i wont run the Programm An and Aus

An is in english on and Aus ist in english off

Thats the program that wont work


term.clear()
term.setCursorPos(1,1)
print("X An")
term.setCursorPos(1,2)
print("X Aus")

while true do
local event, button, X,Y = os.pullEvent("mouse_click")
XY = X..","..Y
end

if XY == "1,1" and button == 1 then
term.clear()
shell.run("An")
end

if XY == "1,2" and button == 1 then
term.clear()
shell.run("Aus")
end
Bomb Bloke #2
Posted 26 March 2016 - 11:55 AM
The code under the loop cannot run if the loop does not end.

term.clear()

term.setCursorPos(1,1)
print("X An")
print("X Aus")

while true do
	local event, button, X,Y = os.pullEvent("mouse_click")

	if X == 1 and Y == 1 and button == 1 then
		term.clear()
		shell.run("An")
	elseif X == 1 and Y == 2 and button == 1 then
		term.clear()
		shell.run("Aus")
	end
end