ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: XSilent_DevilX on Nov 13, 2024, 03:01 AM

Title: Trying to make a monitor-based to-do list
Post by: XSilent_DevilX on Nov 13, 2024, 03:01 AM
Hello, this is my first post on this forum so I apologise if this is the wrong section of the forum.
I am trying to make a to-do list that displays items that need doing on a monitor with the ability to change the color of the text by clicking on each item on the monitor. I want them to be able to change between red, yellow and green text colours. I don't have much experience with interacting with the monitors so any help would be appreciated.

I haven't gotten very far as I dont really know where to begin but here is my code thus far:

local mon = peripheral.wrap("left")
-- Change the text in these brackets to change
-- what the monitor says
local todo1 = "Train infrastructure + Building"
local todo2 = "Train Yard"
local todo3 = "Smeltery"
local todo4 = "Stone Automation"
--
local x = 1
local y = 1
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(x,y)
mon.write(todo1)
mon.setCursorPos(x,y+2)
mon.write(todo2)
mon.setCursorPos(x,y+4)
mon.write(todo3)
mon.setCursorPos(x,y+6)
mon.write(todo4)
Title: Trying to make a monitor-based to-do list
Post by: Lupus590 on Nov 13, 2024, 09:06 AM
If you use term.redirect(mon) then you can use all of the terminal commands that you are familiar with. print will even write to the monitor.

You will be unable to write to the computer's built-in terminal while doing this though.
Title: Trying to make a monitor-based to-do list
Post by: Purrcival on Nov 22, 2024, 02:43 PM
Quote from: XSilent_DevilX on Nov 13, 2024, 03:01 AM-formatting snip-

Try this code. Instead of separate variables, utilize the table instead.
local mon = peripheral.wrap("left")
local cterm = term.current() --gets current terminal
local x, y = 1, 1

local list = {
    "Item 1",
    "Item 2",
    "Item 3",
}

term.redirect(mon) --focus onto monitor
term.setCursorPos(x, y)
for k, v in pairs(list) do
    print(v)
end
term.redirect(cterm) --focus back to original terminal

Hopes this helps optimize your code!