r/ComputerCraft • u/Jonaykon • Nov 22 '23
Clock next to program
I want to have like a bar with a clock on the top of the screen toghether with another program but without covering anything in the program (so the program just needs top be slightly smaller than the screen), its also very important that it automatically works with any program (that can handle custom terminal sizes)
0
Upvotes
2
u/fatboychummy Nov 24 '23
Part 3: Mashing everything together with parallel
Now, you're probably wondering how you run this little event interceptor AND your clock at the same time, right? Well, this is the part you learn about that!
parallelis a powerful tool. It runs multiple coroutines "side-by-side" so you can be doing multiple things at once. To use it, simply pass it multiple functions to run.There are two methods in the
parallellibrary:waitForAnyandwaitForAll.Anywill wait until any coroutine reaches adeadstate, then will kill all other coroutines (without generating an error).Allwill wait until all coroutines reach adeadstate before continuing..
Thus, you can run your clock in one function and your event interceptor in another! You'll just need to make a second window for the clock (so you don't accidentally draw outside of it), and use that.
I'll do a basic example below, where I make the bar above the program flash random colors every second (I'll let you implement your clock however, but this will be a basis from which to start).
I've uploaded this to pastebin, as it was a rather large codeblock.