Posted 05 July 2014 - 01:39 PM
Hello, once again!
I'm currently trying to make desktop on my computer, and I like the time to constantly update at the same time as I do other things on the computer. It has come to my mind that the Parallel API could help me with that. But if I understand it correctly parallel can't handle functions with parameters ex. "printTime(x,y)", or as the matter of facts it can but it will just run the function with parameters not the other one. (Depending on with function declared first). So my question is: is there any way to make it read parameters and still run both functions, without interacting with the "parallel API" code.
This is what i want to do:
As you can see "x" and "y" are used to set the time's place on the screen. If I make a different GUI on the "next" page I may want to change the placing of the displayed time. That's also why i made this particular function. But now lets say I run the parallel API:
I also attached the "Desktop" function, if anyone find it useful:
Suggestions anyone? ;)/>
I'm currently trying to make desktop on my computer, and I like the time to constantly update at the same time as I do other things on the computer. It has come to my mind that the Parallel API could help me with that. But if I understand it correctly parallel can't handle functions with parameters ex. "printTime(x,y)", or as the matter of facts it can but it will just run the function with parameters not the other one. (Depending on with function declared first). So my question is: is there any way to make it read parameters and still run both functions, without interacting with the "parallel API" code.
This is what i want to do:
function printTime(x,y)
while true do
term.setTextColor(colors.lime)
term.setCursorPos(x,y)
print(textutils.formatTime(os.time(), true))
sleep(0)
end
end
As you can see "x" and "y" are used to set the time's place on the screen. If I make a different GUI on the "next" page I may want to change the placing of the displayed time. That's also why i made this particular function. But now lets say I run the parallel API:
parallel.waitForAny(DeskTop,printTime(7,2))
This wont work, but this does: (If you change the "printTime" function a bit, replace "x" and "y" with values)
parallel.waitForAny(DeskTop,printTime)
I also attached the "Desktop" function, if anyone find it useful:
Spoiler
function DeskTop()
function simpleMenu()
running = true
while running do
term.setTextColor(colors.lightBlue)
if selectedItem == 1 then
term.setCursorPos(3,4)
print("[ START: ]")
term.setCursorPos(19,4)
print(" FUNCTIONS: ")
elseif selectedItem == 2 then
term.setCursorPos(3,4)
print(" START: ")
term.setCursorPos(19,4)
print("[ FUNCTIONS: ]")
end
event, key = os.pullEvent("key")
if key == keys.down then
running = false
if selectedItem == 1 then
menu1()
elseif selectedItem == 2 then
menu2()
end
elseif key == keys.left then
if selectedItem == 2 then
selectedItem = selectedItem - 1
end
elseif key == keys.right then
if selectedItem == 1 then
selectedItem = selectedItem + 1
end
end
end
end
function menu1()
local x = 5
running2 = true
while running2 do
if x == 4 then
y = x + 1
term.setCursorPos(3,y)
print(" ")
simpleMenu()
end
term.setTextColor(colors.orange)
if x == 5 then
term.setCursorPos(3,x)
print("->")
elseif x > 4 then
y = x - 1
term.setCursorPos(3,x)
print("->")
term.setCursorPos(3,y)
print(" ")
end
if x < 8 then
y = x + 1
term.setCursorPos(3,x)
print("->")
term.setCursorPos(3,y)
print(" ")
end
event, key = os.pullEvent("key")
if key == keys.up then
if x > 4 then
x = x - 1
end
elseif key == keys.down then
if x < 8 then
x = x + 1
end
elseif key == keys.enter then
if x == 5 then
os.shutdown()
elseif x == 6 then
os.reboot()
elseif x == 7 then
clear()
running2 = false
parallel.waitForAny(DeskTop,printTime)
elseif x == 8 then
clear()
running2 = false
end
end -- END IF-STATEMENT
end -- END LOOP
end -- END FUNCTION menu1
function menu2()
local x = 5
running2 = true
while running2 do
if x == 4 then
y = x + 1
term.setCursorPos(19,y)
print(" ")
simpleMenu()
end
term.setTextColor(colors.orange)
if x == 5 then
term.setCursorPos(19,x)
print("->")
elseif x > 4 and x <= 9 then
y = x - 1
term.setCursorPos(19,x)
print("->")
term.setCursorPos(19,y)
print(" ")
end
if x < 9 and x >= 4 then
y = x + 1
term.setCursorPos(19,x)
print("->")
term.setCursorPos(19,y)
print(" ")
end
event, key = os.pullEvent("key")
if key == keys.up then
if x > 4 then
x = x - 1
end
elseif key == keys.down then
if x < 9 and x >= 4 then
x = x + 1
end
elseif key == keys.enter then
if x == 5 then
running2 = false
ControllPanel()
elseif x == 6 then
Lock()
elseif x == 7 then
Mail()
elseif x == 8 then
elseif X == 9 then
end
end -- END IF-STATEMENT
end -- END LOOP
end -- END FUNCTION menu2
-- RUN ORDER --
clear()
BigBox()
simpleMenu()
end --[[ END DESKTOP ]]--
Suggestions anyone? ;)/>
Edited on 05 July 2014 - 12:09 PM