Jump to content




Monitor Countdown Timer


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

#1 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 04:02 PM

Dear Computercraft Pros,


Im making a purge system with a monitor that countdown timer
But my programming is quite rusty so I was wondering if someone can help me to make a countdowntimer on a monitor

this is the code:
http://pastebin.com/j0Aq8PyR

The plan is when the computer gets a redstonesignal then the timer should run (10 minutes and 20 seconds)
Both timers should run together.
But one starts at 10 minutes and the other one at 5.
The red numbers should count down in the code.
And when it reaches 0 it should send out a redstone signal.

Thank you

Edited by Xixili, 29 August 2015 - 04:03 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 August 2015 - 04:41 PM

local min, sec = 10, 0

while true do
  sleep( 1 )
  if sec == 0 then
    min = min - 1
    sec = 60
  end
  sec = sec - 1
  --#write the numbers here!
  if min == 0 and sec == 0 then
    break
  end
end



#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 29 August 2015 - 04:49 PM

View PostKingofGamesYami, on 29 August 2015 - 04:41 PM, said:

-- snip --
I think Xixili wanted more than 1 timer at a ... time ( :P )


I got pretty carried away when I was writting this...
Here's what I came up with:
http://pastebin.com/F3m9NV90

Don't have time to test it right now... just let me know if you run into any problems, I'll jump into a singleplayer world, and work out the kinks.

Edited by HPWebcamAble, 29 August 2015 - 04:51 PM.


#4 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 05:00 PM

View PostHPWebcamAble, on 29 August 2015 - 04:49 PM, said:

View PostKingofGamesYami, on 29 August 2015 - 04:41 PM, said:

-- snip --
I think Xixili wanted more than 1 timer at a ... time ( :P )


I got pretty carried away when I was writting this...
Here's what I came up with:
http://pastebin.com/F3m9NV90

Don't have time to test it right now... just let me know if you run into any problems, I'll jump into a singleplayer world, and work out the kinks.

Thank you for making some TIME to help me :P

Maybe i did it wrong but when activating the timer I get an error:
startup:40: attempt to index ? (a nil value)

this is how i added your code:
http://pastebin.com/4XrSRm3S

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 August 2015 - 05:07 PM

Change line 5 from timers to timer, or change line 40 and 43 to timers.

#6 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 05:22 PM

View PostKingofGamesYami, on 29 August 2015 - 05:07 PM, said:

Change line 5 from timers to timer, or change line 40 and 43 to timers.

Thank you but it didnt solve the problem
startup:12: attempt to index ? (a nil value)

http://pastebin.com/4XrSRm3S

Im trying to understand the code but sadly I cant find the problem.

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 August 2015 - 05:39 PM

On line 12, you first try to access 'tTime', which works. Next, you try to index 'tTimer', which doesn't. Change 'tTimer' to tTime'.

#8 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 06:16 PM

View PostKingofGamesYami, on 29 August 2015 - 05:39 PM, said:

On line 12, you first try to access 'tTime', which works. Next, you try to index 'tTimer', which doesn't. Change 'tTimer' to tTime'.
Thank you it solved the problem but it doesnt count down as seconds but just a bunch of weird random numbers and then after 5 seconds it stops.

#9 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 07:33 PM

View PostHPWebcamAble, on 29 August 2015 - 04:49 PM, said:

View PostKingofGamesYami, on 29 August 2015 - 04:41 PM, said:

-- snip --
I think Xixili wanted more than 1 timer at a ... time ( :P )


I got pretty carried away when I was writting this...
Here's what I came up with:
http://pastebin.com/F3m9NV90

Don't have time to test it right now... just let me know if you run into any problems, I'll jump into a singleplayer world, and work out the kinks.
Thank you for making a timer but there are many problems with it.
I got it working but when 1 minute has passed it keeps counting like -9, -8, -7 and so on.

Also when the 5 minute timer has run out it needs to send a bundledcable orange signal

and when the 10 minute timer has run out it needs to send to a red cable.

sorry for so many questions.

#10 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 29 August 2015 - 07:50 PM

View PostXixili, on 29 August 2015 - 07:33 PM, said:

Also when the 5 minute timer has run out it needs to send a bundledcable orange signal

and when the 10 minute timer has run out it needs to send to a red cable.

Ah, I thought it was only when both ran out.
Ok, I'll do some testing, this time I'll make sure it works :)
Should take about 30 minutes or so.

View PostXixili, on 29 August 2015 - 07:33 PM, said:

sorry for so many questions.

Its fine, thats why we are here!

#11 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 29 August 2015 - 08:30 PM

Ok, I think it should work now

http://pastebin.com/r5Fyqcy6


I changed a few of the sides, you'll want to look through it and change them back to match your setup.
Another thing, for each timer, it runs the associated function a second AFTER the timer hits 0. Hope thats ok :)

#12 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 29 August 2015 - 09:17 PM

View PostHPWebcamAble, on 29 August 2015 - 08:30 PM, said:

Ok, I think it should work now

http://pastebin.com/r5Fyqcy6


I changed a few of the sides, you'll want to look through it and change them back to match your setup.
Another thing, for each timer, it runs the associated function a second AFTER the timer hits 0. Hope thats ok :)

Perfect it works!

Last question.
Is it possible if the computer recieves a redstone signal at the bottom before the 5 minute timer runs out that the countdown stops (os.reboot() for example)
And after 5 minutes that if he recieves a signal at the bottom then it wont reboot?

#13 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 29 August 2015 - 10:29 PM

View PostXixili, on 29 August 2015 - 09:17 PM, said:

Last question.
Is it possible if the computer recieves a redstone signal at the bottom before the 5 minute timer runs out that the countdown stops (os.reboot() for example)
And after 5 minutes that if he recieves a signal at the bottom then it wont reboot?

http://pastebin.com/7BKuLQx6
Should work.. I think, cant test at the moment

#14 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 30 August 2015 - 12:02 AM

View PostHPWebcamAble, on 29 August 2015 - 10:29 PM, said:

View PostXixili, on 29 August 2015 - 09:17 PM, said:

Last question.
Is it possible if the computer recieves a redstone signal at the bottom before the 5 minute timer runs out that the countdown stops (os.reboot() for example)
And after 5 minutes that if he recieves a signal at the bottom then it wont reboot?

http://pastebin.com/7BKuLQx6
Should work.. I think, cant test at the moment

I checked it and it works fine.
Thank you very much





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users