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

help from one programmer to another?

Started by Drako365, 16 May 2013 - 09:29 AM
Drako365 #1
Posted 16 May 2013 - 11:29 AM
topic: help from one programmer to another?

I am playing tekkit classic (Yes, I know, old stuff.) and am wondering if I could use a computer to maintain an average pulse per minute.
I know it's possible, and I could program it in C, but Lua escapes me.(I simply don't use it much/at all)
It would take input from the bottom, calculate the stuff, and display the numbers on a monitor on its top.

Thank you.
CtrlAltElite #2
Posted 17 May 2013 - 01:37 PM
You can use the

sleep(x)
function. You replace X with the number of seconds, in your case 60, you want it to sleep for.
Lyqyd #3
Posted 17 May 2013 - 02:07 PM
The biggest issue is that there isn't any sort of access to system clock time. You've got "CPU" time, which (IIRC) is related to server ticks (if the server is at 10tps instead of 20tps, this would seem to dilate time by a factor of two), and Minecraft world time. If you're satisfied with the average being over 1200 ticks rather than 60 real seconds, it's going to be much easier to accomplish this. Essentially, you'll want a loop that uses os.pullEvent(), with handlers for redstone and timer events, for handling pulse quantity tracking and display updates. You'd look at the value returned by os.clock() each time a pulse completed and perform whatever operations you needed.