Jump to content




Help me with os.time() please


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

#1 spyman68

  • Members
  • 155 posts

Posted 16 March 2013 - 01:52 PM

FIXED. Curtsy of TheOriginalBIT Now it doesn't let me use the other functions of my OS(I can't click on any of my stuff)

#2 Zoinky

  • Members
  • 144 posts
  • LocationWellington, New Zealand

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.

#3 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 16 March 2013 - 02:08 PM

Parallels; Look it up on the wiki

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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 )


#5 spyman68

  • Members
  • 155 posts

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

#6 spyman68

  • Members
  • 155 posts

Posted 17 March 2013 - 01:20 AM

View PostSuicidalSTDz, on 16 March 2013 - 02:08 PM, said:

Parallels; Look it up on the wiki
Parallels aren't on the the wiki...

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 March 2013 - 01:22 AM

View Postspyman68, on 17 March 2013 - 01:20 AM, said:

Parallels aren't on the the wiki...
It is indeed wiki link

#8 spyman68

  • Members
  • 155 posts

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
Spoiler
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.

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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 )


#10 spyman68

  • Members
  • 155 posts

Posted 17 March 2013 - 02:02 AM

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:

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 March 2013 - 02:13 AM

View Postspyman68, on 17 March 2013 - 02:02 AM, said:

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:
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.

#12 spyman68

  • Members
  • 155 posts

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.

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 March 2013 - 02:31 AM

Ok then...

#14 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 17 March 2013 - 03:47 AM

See kids, aren't parallels fun! ^_^

#15 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 17 March 2013 - 06:17 AM

View PostZoinky, on 16 March 2013 - 02:01 PM, said:

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.

View PostSuicidalSTDz, on 16 March 2013 - 02:08 PM, said:

Parallels; Look it up on the wiki

Could use this though, prefer it actually

#16 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 March 2013 - 03:55 PM

View PostSuicidalSTDz, on 17 March 2013 - 03:47 AM, said:

See kids, aren't parallels fun! ^_^
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.



View Postcube123, on 17 March 2013 - 06:17 AM, said:

View PostZoinky, on 16 March 2013 - 02:01 PM, said:

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.

View PostSuicidalSTDz, on 16 March 2013 - 02:08 PM, said:

Parallels; Look it up on the wiki

Could use this though, prefer it actually
Coroutines and parallel is the same. parallel is just managed coroutines.

#17 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 17 March 2013 - 04:04 PM

Screw parallels and coroutines! Vectors are the next big thing!

vector.new(gps.locate(TheOriginalBIT))
Muahahaha!

#18 spyman68

  • Members
  • 155 posts

Posted 18 March 2013 - 02:16 AM

BTW, this problem is solved thanks to TheOriginalBIT, he solved my first problem AND my second problem

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#20 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 18 March 2013 - 02:25 PM

THEORIGINALBIT: You know HTTP also uses events?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users