Jump to content




[HELP][LUA] Need help!


  • You cannot reply to this topic
4 replies to this topic

#1 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 09 April 2013 - 11:11 PM

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

What am I doing wrong?

#2 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 09 April 2013 - 11:53 PM

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


#3 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 10 April 2013 - 12:08 AM

I want it to update the time automaticly and then print the updated time.
(Sorry for any bad English)

#4 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 10 April 2013 - 03: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


#5 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 10 April 2013 - 04:23 AM

Thank You!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users