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

Simple TODO SYSTEM Using ADV Mon And Computer

Started by DusterTheFirst, 24 June 2016 - 06:31 PM
DusterTheFirst #1
Posted 24 June 2016 - 08:31 PM
I am trying to make a todo system where i can add or remove things from the lis. i thought that having a file that i edit with all the todos on it that would just be printed to a montor is the easyest rout but as this shows it was a far fetched idea.

so i guess my question now is how would i make a simple todo system that i could implement in my program that would be simple and edited from the monitor(like deleting them)
Bomb Bloke #2
Posted 25 June 2016 - 03:14 AM
The short answer is "stick each entry in a table, draw it on the monitor, wait for user input".

The long answer is, how are you going to add entries via an external monitor? Do you have specific plans for text entry?
DusterTheFirst #3
Posted 25 June 2016 - 09:04 PM
The short answer is "stick each entry in a table, draw it on the monitor, wait for user input".

The long answer is, how are you going to add entries via an external monitor? Do you have specific plans for text entry?
i have a system set up with a main computer running this As 'STARTUP':

--peripherals--
title = peripheral.wrap("monitor_2")
status = peripheral.wrap("monitor_3")
auto = peripheral.wrap("monitor_4")
gencell = peripheral.wrap("monitor_5")
advcell = peripheral.wrap("monitor_6")
react = peripheral.wrap("monitor_7")
energy = peripheral.wrap("monitor_8")
todo = peripheral.wrap("monitor_9")
deviders ={peripheral.wrap("monitor_10"), peripheral.wrap("monitor_11"), peripheral.wrap("monitor_12"), peripheral.wrap("monitor_13"), peripheral.wrap("monitor_14"), peripheral.wrap("monitor_15"), peripheral.wrap("monitor_16"), peripheral.wrap("monitor_17")}
wireless = peripheral.wrap("top")
--functions--
function resetAllDefaults()
titleInit()
reset(status, "-------CONNECTED DEVICES-------")
reset(auto, "-------AUTOCRAFTING STATUS-------")
reset(gencell, "-------GENERAL CELL INFO-------")
reset(advcell, "-------ADVANCED CELL INFO-------")
reset(react, "-------REACTOR INFO-------")
reset(energy, "-------ENERGY STORAGE INFO-------")
reset(todo, "-------TO DO-------")
end
local function centerText(screen, text)
  local x, y = screen.getSize()
  local x2, y2 = screen.getCursorPos()
  screen.setBackgroundColor(colors.gray)
  screen.setCursorPos((math.ceil(x / 2) - (text:len() / 2)), y2)
  screen.write(text)
end
function reset(toReset, titleofscreen)
  toReset.setBackgroundColor(colors.gray)
  toReset.clear()
  toReset.setBackgroundColor(colors.black)
  toReset.setCursorPos(1,1)
  toReset.setTextColor(colors.yellow)
  centerText(toReset, titleofscreen)
  toReset.setCursorPos(1,2)
end
function titleInit()
  title.setBackgroundColor(colors.gray)
  title.clear()
  title.setCursorPos(1,1)
  title.setTextScale(2.5)
  title.setTextColor(colors.lightGray)
  centerText(title, "Dust Labs' Wall Of Data")
  title.setCursorPos(1,2)
  centerText(title, "Powered By DustOS")
end
function writeToAllDevs(text)
end
function InitWireless()
  if wireless.isWireless() then
    rednet.open("top")
  end
end
function checkRemote()
  local file = fs.open("rednet", "r")
  message = file.readLine()
  file.close()
  resetRednet()
  if message ~= "nil" then
    if message == "reboot" then
	  os.reboot()
    elseif message == "restart" then
	  os.reboot()
    elseif message == "ping" then
	  rednet.broadcast("pong")
    end
  end
end
function resetRednet()
  local clear = "nil"
  local file2 = fs.open("rednet", "w")
  file2.write(clear)
  file2.close()
end
function tellRemote(message)
  rednet.broadcast(message)
end
--statics--
--variables--
--MAIN--
rem = multishell.launch({}, "remote")
multishell.setTitle(rem, "Remote Manager/LOG")
multishell.setTitle(multishell.getCurrent(), "MAIN")
InitWireless()
resetAllDefaults()
deviders[1].write("devidr")
loop = 0
while true do
loop = loop + 1
if loop > 10 then
  loop = 0
end
--tick(check for data)--
checkRemote()
if loop == 9 then
-- multishell.launch({}, "todo")
end
--render(draw to screen)--
--set vars--
--sleep--
sleep(.1)
--end--
end
And This As 'REMOTE':

while true do
  ID, message = rednet.receive()
  print(message)
  file = fs.open("rednet", "w")
  file.write(message)
  file.close()
end
And A Pocket Computer Running This as 'STARTUP':

function init()
 
  rednet.open("back")
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.gray)
  term.clear()
  term.setTextColor(colors.yellow)
  print("Dust Wall Of Data Remote")
  term.setTextColor(colors.lightGray)
  term.setCursorBlink(true)
  x = 1
  y = 2
end
function enter()
  if y > 19 then
    y = y
  else
    y = y + 1
  end
  term.setCursorPos(x,y)
end
--MAIN
init()
while true do
  term.write(">")
  inp = read()
  enter()
  if inp == "end" then
    term.setBackgroundColor(colors.black)
    term.clear()
    term.setCursorPos(1,1)
    term.setTextColor(colors.yellow)
    print("Dust OS Program Launcher")
    break
  elseif inp == "clear" then
    init()
  elseif inp == "ping" then
    rednet.broadcast("ping")
    start = os.clock()
    PID, pong = rednet.receive(5)
    elapsed = os.clock() - start
    if pong ~= nil then
	  print("Computer #" .. PID .. " Sent:" .. pong)
	  enter()
	  print("After " .. elapsed .. " seconds")
	  enter()
    else
	  print("TIMED OUT AFTER " .. elapsed .. " Seconds")
	  enter()
    end
  elseif inp == "help" then
    print("-------Help-------")
    enter()
    print("Serverhelp - Server Side")
    enter()
    print("Clienthelp - Client Side")
    enter()
  elseif inp == "serverhelp" then
    print("-------Server Help-------")
    enter()
  elseif inp == "clienthelp" then
    print("-------Client Help-------")
    enter()
  elseif inp == "options" then
    print("-------Options-------")
    enter()
  elseif inp == "todo" then
    print("-------TODO-------")
    enter()
    print("To Edit Todo Use The Edit")
    enter()
    print("Computers")
  else
    rednet.broadcast(inp)
  end
end

the system is set up so the main program receives messages sent from the pocket computer. i want the player to be able to type in "todo" and it will open a TODO tab whitch they will be able to input "add <message>" "remove <#>" or "Move <#> <#>"

If You Need Any More Info Just Ask
Bomb Bloke #4
Posted 26 June 2016 - 12:35 PM
I don't see any particular reason to have your "remote" script as separate to you main code. Better to merge it and do away with the "rednet" file.

In the main while loop of your startup script, simply pull all events, and use if/then blocks to check which type you get. If it's a "rednet_message", then add an entry received from the pocket computer. If it's a "monitor_touch", perhaps remove a message depending on where your monitor was pressed.
DusterTheFirst #5
Posted 26 June 2016 - 01:01 PM
I don't see any particular reason to have your "remote" script as separate to you main code. Better to merge it and do away with the "rednet" file.

In the main while loop of your startup script, simply pull all events, and use if/then blocks to check which type you get. If it's a "rednet_message", then add an entry received from the pocket computer. If it's a "monitor_touch", perhaps remove a message depending on where your monitor was pressed.
oh ok. that would simplify it a lot. but wouldn't that have a delay where the script is rendering the monitors and it would void your entry when you inputted text then? i would still have to run rednet.recieve to get the message. if I use modem_message, i h=get a table in the input perameter
Edited on 26 June 2016 - 11:47 AM
Bomb Bloke #6
Posted 26 June 2016 - 02:38 PM
rednet_message events are different to modem_message events - you're interested in the former, not the latter.

You don't have to call rednet.receive(), see - you can manually collect rednet messages via os.pullEvent(). Loosely put, this:

local senderID, message = rednet.receive()

… is equivalent to this:

local event, senderID, message = os.pullEvent("rednet_message")

… which can in turn be managed in conjunction with other events like this:

local event = {os.pullEvent()}

if event[1] == "rednet_message" then
  -- event[2] is the senderID, event[3] is the message

elseif event[1] == "monitor_touch" then
  -- event[2] is the monitor side, event[3] is the x co-ord, event[4] is the y co-ord

end