How to make a second and milisecond countdown

Maybe this video might help

Well seeing as my delay is the same as everyone elseā€™s, than whatā€™s the big deal? If Iā€™m using the best practice, why would you argue about that? You said: there is no difference between what you did and what everybody said.

But the difference was what I stated above. Everyone is using while loops, while Iā€™m using a for loop. (Which is a better practice in this situation, as we donā€™t need to loop infinitely, but instead, we will only loop for the amount of time necessary.)

As far as I can see, youā€™ve provided 0 scripts to add to this thread, so you have no place to be judging my code, especially when you said task.wait() was better, yourself. Now weā€™re done arguing about this, but if you have any questions, refer to the API Docs on loops.

1 Like

Iā€™m not one to get involved in arguments, but for what itā€™s worth, I donā€™t see anything wrong with your code. It fulfills the OP requirements. My code is more precise since it actually uses the return value from task.wait() to subtract from seconds. Since task.wait() always returns the actual amount of time that it waited, there is no danger of it going into an infinite loop.

Besides, on a related note, most operating system kernels program PIT (Programmable Interval Timer) channel 0 to provide an output frequency of 1000 Hz (1 kHz, or pulse at 1,000 times per second). Timer channel 0 is hardwired to PIC (Programmable Interrupt Controller) channel 0 (INT 0) which is the highest priority hardware interrupt outside of NMI (Non-Maskable Interrupt) and RESET. The INT 0 ISR (Interrupt Service Routine) vectors into kernel space and eventually reaches the scheduler which determines the next thread to run. So there is no way to get a millisecond timer unless one gets it from the operating system kernel itself. Low level and bare metal coding are my specialties as a system software engineer.