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

How to make os.sleep, os.startTimer?

Started by LeDark Lua, 02 January 2016 - 09:53 AM
LeDark Lua #1
Posted 02 January 2016 - 10:53 AM
Ok I'm making a project, and I need to make os.sleep and os.startTimer, but how?
Creator #2
Posted 02 January 2016 - 11:41 AM
Why would you want to make it? Sleep works like this:

local timer = os.startTimer()

repeat
local event, tmr = coroutine.yield("timer")
until tmr == timer
Edited on 02 January 2016 - 10:42 AM
LeDark Lua #3
Posted 02 January 2016 - 11:50 AM
I know how it works, but I want to make it, because it bugs out the buffer I made. Or its my buffer, can't tell
Lignum #4
Posted 02 January 2016 - 12:56 PM
I know how it works, but I want to make it, because it bugs out the buffer I made. Or its my buffer, can't tell
It's usually a good idea to blame your own code until you can solidly prove that it's someone else's code's fault. So it's probably your buffer.

Anyway, there is no way to reimplement os.startTimer without using os.startTimer. The actual timer stuff is done natively.
Wojbie #5
Posted 02 January 2016 - 01:01 PM
I know how it works, but I want to make it, because it bugs out the buffer I made. Or its my buffer, can't tell
It's usually a good idea to blame your own code until you can solidly prove that it's someone else's code's fault. So it's probably your buffer.

Anyway, there is no way to reimplement os.startTimer without using os.startTimer. The actual timer stuff is done natively.
So the question is. What are you trying to do with your buffer and how its bugging?
LeDark Lua #6
Posted 02 January 2016 - 01:33 PM
I'm trying to run worm on it, or any program that uses term/paintutils.
Bug: it like shifts itself upwards
Edited on 02 January 2016 - 01:21 PM
Lyqyd #7
Posted 02 January 2016 - 05:06 PM
Definitely a problem in your code. Post your code.
LeDark Lua #8
Posted 02 January 2016 - 05:56 PM
My code: pastebin
or

pastebin get LAejwLBZ gl

Usage:

os.loadAPI( "gl" )
local buffer = gl.create(x, y, width, height)
buffer:clear( backgroundColor, textColor )
buffer:clearLine( y, backgroundColor, textColor )
buffer:drawChar( x, y, char, backgroundColor, textColor )
buffer:drawText( x, y, text, backgroundColor, textColor )
local aTerm = buffer:getTerm()
buffer:draw( term )

Make a main buffer according to your screen, then make a program buffer and draw that on the main buffer.
Edited on 02 January 2016 - 05:01 PM