Jump to content




How to make os.sleep, os.startTimer?


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

#1 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

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?

#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

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 by Creator, 02 January 2016 - 11:42 AM.


#3 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

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

#4 Lignum

  • Members
  • 558 posts

Posted 02 January 2016 - 12:56 PM

View PostLeDark Lua, on 02 January 2016 - 11:50 AM, said:

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.

#5 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 02 January 2016 - 01:01 PM

View PostLignum, on 02 January 2016 - 12:56 PM, said:

View PostLeDark Lua, on 02 January 2016 - 11:50 AM, said:

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?

#6 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

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 by LeDark Lua, 02 January 2016 - 02:21 PM.


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 January 2016 - 05:06 PM

Definitely a problem in your code. Post your code.

#8 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

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 by LeDark Lua, 02 January 2016 - 06:01 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users