7 posts
Posted 21 February 2015 - 05:58 PM
I have a problem with the program I wrote but I have no idea how to fix it! I've been searching everywhere but I can't find a solution. I'm a beginner so I would love to have some help!
The problem is that the monitor is not getting it's clock updated as the loop should do! the program is for an over-complicated To Do List just so I have a little project to work on.
here is the code:
mon = peripheral.wrap("right")
function list()
local input2 = read()
if input2 == ("stop") then
start()
else
print("Unknown Command")
list()
end
shell.run("ToDoList")
while not guess == 3 do
sleep(0.3)
time = os.time()
atime = textutils.formatTime(time, false)
mon.setCursorPos(10,26)
mon.write("Day " .. tostring(os.day()))
mon.setCursorPos(1,26)
mon.write(atime)
end
end
function start()
term.clear()
term.setCursorPos(1, 1)
print("Enter Command: ")
local input = read()
if input == ("exit") then
os.reboot()
elseif input == "list" then
list()
start()
else
print("Unknown Command")
start()
end
end
start()
957 posts
Location
Web Development
Posted 21 February 2015 - 08:39 PM
What I think is happening is your program never gets to the loop
I'm bored so I rewrote your program
I used the Parallel API. I'd bet you haven't used it before, but it's pretty simple. Here is the Wiki for it:
http://computercraft.info/wiki/Parallel_%28API%29
mon = peripheral.wrap("right")
function list()
--#shell.run("ToDoList") No idea what this is. Probably another program of yours?
while true do
sleep(1)
local cTime = os.time()
cTime = textutils.formatTime(cTime, false)
mon.setCursorPos(10,26)
mon.write("Day " .. tostring(os.day()))
mon.setCursorPos(1,26)
mon.write(atime)
end
end
function getInput()
while true do --#loops forever
local input = read() --#Waits for input
if input == "stop" then
break --#stops the loop
else
print("Unknown Command")
end
end
end
while true do --#Continues forever
term.clear()
term.setCursorPos(1, 1)
print("Enter Command:")
local input = read()
if input == "list" then
parallel.waitForAny(list,getInput) --#Basically this allows both to run at the same time. When either stops, the other is also stopped
elseif input == "exit" then
print("Exiting...")
sleep(1)
break --#Stops the loop
else
print("Unknown command")
end
end
7 posts
Posted 21 February 2015 - 10:15 PM
What I think is happening is your program never gets to the loop
I'm bored so I rewrote your program
I used the Parallel API. I'd bet you haven't used it before, but it's pretty simple. Here is the Wiki for it:
http://computercraft...allel_%28API%29
mon = peripheral.wrap("right")
function list()
--#shell.run("ToDoList") No idea what this is. Probably another program of yours?
while true do
sleep(1)
local cTime = os.time()
cTime = textutils.formatTime(cTime, false)
mon.setCursorPos(10,26)
mon.write("Day " .. tostring(os.day()))
mon.setCursorPos(1,26)
mon.write(atime)
end
end
function getInput()
while true do --#loops forever
local input = read() --#Waits for input
if input == "stop" then
break --#stops the loop
else
print("Unknown Command")
end
end
end
while true do --#Continues forever
term.clear()
term.setCursorPos(1, 1)
print("Enter Command:")
local input = read()
if input == "list" then
parallel.waitForAny(list,getInput) --#Basically this allows both to run at the same time. When either stops, the other is also stopped
elseif input == "exit" then
print("Exiting...")
sleep(1)
break --#Stops the loop
else
print("Unknown command")
end
end
Thanks for that! I should be able to figure that one out :P/> I hope it doesn't bring other problems and yes the ToDoList is another program just to save some space! It just places a list on the monitor on the right!
7 posts
Posted 21 February 2015 - 11:13 PM
What I think is happening is your program never gets to the loop
I'm bored so I rewrote your program
I used the Parallel API. I'd bet you haven't used it before, but it's pretty simple. Here is the Wiki for it:
http://computercraft...allel_%28API%29
mon = peripheral.wrap("right")
function list()
--#shell.run("ToDoList") No idea what this is. Probably another program of yours?
while true do
sleep(1)
local cTime = os.time()
cTime = textutils.formatTime(cTime, false)
mon.setCursorPos(10,26)
mon.write("Day " .. tostring(os.day()))
mon.setCursorPos(1,26)
mon.write(atime)
end
end
function getInput()
while true do --#loops forever
local input = read() --#Waits for input
if input == "stop" then
break --#stops the loop
else
print("Unknown Command")
end
end
end
while true do --#Continues forever
term.clear()
term.setCursorPos(1, 1)
print("Enter Command:")
local input = read()
if input == "list" then
parallel.waitForAny(list,getInput) --#Basically this allows both to run at the same time. When either stops, the other is also stopped
elseif input == "exit" then
print("Exiting...")
sleep(1)
break --#Stops the loop
else
print("Unknown command")
end
end
Thanks for that! I should be able to figure that one out :P/> I hope it doesn't bring other problems and yes the ToDoList is another program just to save some space! It just places a list on the monitor on the right!
second problem! It doesn't work for me -_-/>