Jump to content




time and menu simultanously?


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

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 June 2013 - 11:29 AM

Hello all,
I triy to make a program, that has a menu and shows the time at once.
But if I run it in a parallel it wont work!
Code
local function menu()
--some crappy menu things
end

local function time()
While true do
term.setCursorPos(1,1)
term.write(textutils.formatTime(os.time(), true)
sleep(10)
end
end
parallel.waitForAny(menu, time)
whats wrong?


#2 ElvishJerricco

  • Members
  • 803 posts

Posted 21 June 2013 - 11:48 AM

First, tabs in your code would be nice.

Second, your "while" is capitalized but I'm assuming it's not like that in your code, because that would be an obvious problem.

Third, your menu function is looping infinitely, right? And waiting for events to update itself? If not, then menu is finishing and waitForAny is finishing because of that.

Finally, make sure your menu code isn't drawing over the time text after the time gets written.

#3 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 21 June 2013 - 11:50 AM

Well it only runs one time
Try todo this instead
while true do
  parallel.waitForAny(menu,time)
end

EDIT: Damn ninja's..

#4 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 June 2013 - 11:56 AM

View PostElvishJerricco, on 21 June 2013 - 11:48 AM, said:

First, tabs in your code would be nice.

Second, your "while" is capitalized but I'm assuming it's not like that in your code, because that would be an obvious problem.

Third, your menu function is looping infinitely, right? And waiting for events to update itself? If not, then menu is finishing and waitForAny is finishing because of that.

Finally, make sure your menu code isn't drawing over the time text after the time gets written.
1. I know, but hard to do with mobile :D
2. It's because I'm at my mobile
3. Yes it loops infinite
4.It isn't drawing over the time

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 June 2013 - 11:58 AM

is that a deliberate sleep(10) for the time loop? or do you have it as sleep(1) in the code?

#6 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 June 2013 - 12:05 PM

View Posttheoriginalbit, on 21 June 2013 - 11:58 AM, said:

is that a deliberate sleep(10) for the time loop? or do you have it as sleep(1) in the code?

In my real code I have sleep(.025) :@

#7 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 21 June 2013 - 12:44 PM

If you think about it, a Minecraft day contains 24000 ticks = 1200 seconds (= 20 minutes), while a real day contains 1440 minutues - that means that the formatted time returned by textutils.formatTime changes in every 1200 / 1440 = 1 / 1,2 = 0,833333 seconds. Use that instead of 0,025.

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 21 June 2013 - 05:37 PM

In this case, it might be easier to set your menu code to wait for a keypress event or a timer event. If it gets either, then it updates the display - changing the selected line and the displayed time. Whenever the timer event gets caught it'd set a new one rigged to expire within a very short period.

I'm also suspecting the current menu code is interfering.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users