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

[HELP][LUA] Need help!

Started by Mackan90096, 09 April 2013 - 10:11 PM
Mackan90096 #1
Posted 10 April 2013 - 12:11 AM
Hi!
I have a problem!
I'm trying to make a program that prints the time and a button to exit it.
I can run the program but the button won't do anything.

Heres my code:
Spoiler

function main()
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(1,1)
print("The time is: ")
term.setCursorPos(1,3)
print(textutils.formatTime(os.time(), true))
term.setCursorPos(1,5)
print("[Exit]")
slc = 0
sleep(1)
main()

while true do
event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  if slc == 0 then
   if x >= 1 and x <= 6 and y == 5 and button == 1 then
  term.clear()
   term.setCursorPos(1,1)
   print("Exited!")
   sleep(5)
	os.reboot()
	else
  main()
end
end
end
end
end




main()

What am I doing wrong?
LordIkol #2
Posted 10 April 2013 - 12:53 AM
you forgot the end at the end of your function


function main()
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(1,1)
print("The time is: ")
term.setCursorPos(1,3)
print(textutils.formatTime(os.time(), true))
term.setCursorPos(1,5)
print("[Exit]")
slc = 0
sleep(1)
end
main()

while true do
event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  if slc == 0 then
   if x >= 1 and x <= 6 and y == 5 and button == 1 then
  term.clear()
   term.setCursorPos(1,1)
   print("Exited!")
   sleep(5)
        os.reboot()
        else
  main()
end
end
end
end
Mackan90096 #3
Posted 10 April 2013 - 01:08 AM
I want it to update the time automaticly and then print the updated time.
(Sorry for any bad English)
LordIkol #4
Posted 10 April 2013 - 04:49 AM
No need to be sorry for the language my english is not better :D/>

here is the code for autoupdating time



function main()
while true do
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(1,1)
print("The time is: ")
term.setCursorPos(1,3)
print(textutils.formatTime(os.time(), true))
term.setCursorPos(1,5)
print("[Exit]")
slc = 0
sleep(1)
end
end

function catchmouse()
event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  if slc == 0 then
   if x >= 1 and x <= 6 and y == 5 and button == 1 then
  term.clear()
   term.setCursorPos(1,1)
   print("Exited!")
   sleep(5)
        os.reboot()
        else
  main()
end
end
end
end

while true do
 parallel.waitForAny(main, catchmouse)
 end
Mackan90096 #5
Posted 10 April 2013 - 05:23 AM
Thank You!