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

[Multitasking] Need Help With A Program

Started by PrinzJuliano, 02 September 2013 - 01:48 PM
PrinzJuliano #1
Posted 02 September 2013 - 03:48 PM
Hello Guys,

I just wanna run a function (maybe with parallel api) while i run normal shell & programs

Can you please help me fix my problem?

Thank u guys
PrinzJuliano #2
Posted 02 September 2013 - 04:00 PM
Solved my self:

Code:

monitor = peripheral.wrap("right")
function doClock()
while true do
monitor.clear()
monitor.setCursorPos(1,1)
monitor.write(textutils.formatTime(os.time(),true))
sleep(0.01)
end
end
function doShell()
shell.run("shell")
end
parallel.waitForAny(doClock,doShell)

It would be nice if i find a better suggestion
Kingdaro #3
Posted 02 September 2013 - 04:07 PM
Yeah, you pretty much nailed it right there.

Also, for the record, sleep can only work in increments of 0.05, so 0.05, 0.10, 0.15 etc. will work, but 0.01 will just be upped to 0.05.

And for the future, whenever you don't feel like implementing multitasking functionality into your programs, a lot of operating systems / desktop environments / graphical shells allow multitasking capabilities:
Cannon OS
CraftBang
LyqydOS
Flutter