This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Help me with os.time() please
Started by spyman68, 16 March 2013 - 12:52 PMPosted 16 March 2013 - 01:52 PM
Posted 16 March 2013 - 02:01 PM
Could we see the code for your OS? You can't have the code pause, because then the function won't be executed until later.
Posted 16 March 2013 - 02:08 PM
Parallels; Look it up on the wiki
Posted 16 March 2013 - 09:44 PM
local sX, sY = term.getSize()
local function updateTime()
local updateTimer = os.startTimer( 1 )
while true do
local _, p = os.pullEventRaw( 'timer' )
if p == updateTimer then
local cx, cy = term.getCursorPos() -- if you have functions that write a lot, you will need this
local t = textutils.formatTime( os.time(), false )
term.setCursorPos( sX - #t, 1 )
write( t )
term.setCursorPos( cx, cy )
end
end
end
local function otherMainFunction()
while true do
...
end
end
parallel.waitForAny( updateTime, otherMainFunction )
Posted 17 March 2013 - 01:09 AM
RemiX, the time goes up 2 seconds then I can't click anything and it just freezes my os, other then that I think it works
Posted 17 March 2013 - 01:20 AM
Parallels aren't on the the wiki…Parallels; Look it up on the wiki
Posted 17 March 2013 - 01:22 AM
It is indeed wiki linkParallels aren't on the the wiki…
Posted 17 March 2013 - 01:29 AM
Ok, well TheOriginalBIT do you know how I would go about using this for a timer? The code I have for it is
I'm not sure how to make it keep updateing because if I use 'while true do' then It stops after a certain amount of time with an error.
Spoiler
function titleTime()
term.setBackgroundColor(8)
term.setTextColor(128)
term.setCursorPos(43,1)
print(textutils.formatTime(os.time()).." ")
end
Posted 17 March 2013 - 01:46 AM
the code i will suggest will be like what remiX suggested… whats the error that you are getting?
local function runOs()
while true do
-- os code
-- this needs to have a sleep or a os.pullEvent in it so that it yields and doesnt stop the program from running
end
end
local function timeUpdate()
local timeUpdate = os.startTimer( 1 )
while true do
local _, triggered = os.pullEventRaw( 'timer' )
if triggered == timeUpdate then
titleTime()
timeUpdate = os.startTimer( 1 )
end
end
end
parallel.waitForAny( timeUpdate, runOs )
Posted 17 March 2013 - 02:02 AM
Thank you sooooooo much TheOriginalBIT, your's worked but for some reason remiX's didn't. :D/>I typed the new problem in the first post. Please help with this too :lol:/> :ph34r:/>
Posted 17 March 2013 - 02:13 AM
Oh haha, I see why remixes doesn't, he never restarts the timer :P/> for the new error you will have to post your code. it doesn't make sense as to why it wouldn't work.Thank you sooooooo much TheOriginalBIT, your's worked but for some reason remiX's didn't. :DI typed the new problem in the first post. Please help with this too :lol:/> :ph34r:/>
Posted 17 March 2013 - 02:30 AM
I will PM you my OS because I don't want everyone to know it but I trust you.
Posted 17 March 2013 - 02:31 AM
Ok then…
Posted 17 March 2013 - 03:47 AM
See kids, aren't parallels fun! ^_^/>
Posted 17 March 2013 - 06:17 AM
Could we see the code for your OS? You can't have the code pause, because then the function won't be executed until later.
He could always use coroutine.
Parallels; Look it up on the wiki
Could use this though, prefer it actually
Posted 17 March 2013 - 03:55 PM
You know whats more fun……. pull event loops :P/> 9.8/10 coroutines don't need to be used and can be replaced with a simple pull event loop… I've only ever needed to use a coroutine once in all my programs and its cctube. networking runs in its own coroutine so that the http calls can be made but the gui can still update and such.See kids, aren't parallels fun! ^_^/>
Coroutines and parallel is the same. parallel is just managed coroutines.Could we see the code for your OS? You can't have the code pause, because then the function won't be executed until later.
He could always use coroutine.Parallels; Look it up on the wiki
Could use this though, prefer it actually
Posted 17 March 2013 - 04:04 PM
Screw parallels and coroutines! Vectors are the next big thing!
vector.new(gps.locate(TheOriginalBIT))
Muahahaha!Posted 18 March 2013 - 02:16 AM
BTW, this problem is solved thanks to TheOriginalBIT, he solved my first problem AND my second problem
Posted 18 March 2013 - 09:01 AM
AND it was solved by removing the coroutines and modifying the pull event loop… Just saying 9.8/10…. :P/>
Posted 18 March 2013 - 02:25 PM
THEORIGINALBIT: You know HTTP also uses events?
Posted 18 March 2013 - 02:32 PM
THEORIGINALBIT: You know HTTP also uses events?
Yes I do know http uses events, but it would be weird for our GUI handler (which is the main event loop) to also handle the networking. So there is a separate routine for networking.