Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- function to check for the file
- function fileExists(fileName)
- local file = fs.open(fileName, "r")
- if file then
- file.close()
- return true
- end
- return false
- end
- -- name of the file that will display the text
- local fileName = "text.txt"
- -- connect monitor to console
- local monitor = peripheral.wrap("top") -- top, bottom, left, right
- if monitor then
- -- clear monitor and reset text position
- monitor.clear()
- monitor.setCursorPos(1, 1)
- -- text size, text color and monitor background color https://computercraft.info/wiki/Colors_(API)
- monitor.setTextColor(1)
- monitor.setTextScale(1)
- monitor.setBackgroundColor(32768)
- -- checking for file
- if fileExists(fileName) then
- -- open file
- local file = fs.open(fileName, "r")
- -- reading the file
- local lines = {}
- while true do
- local line = file.readLine()
- if line == nil then break end
- table.insert(lines, line)
- end
- -- file close
- file.close()
- -- file display
- for i, line in ipairs(lines) do
- -- if the line is not empty then display
- if line ~= "" then
- monitor.write(line)
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y + 1) -- next line
- end
- end
- else
- monitor.write("Display file not found.")
- end
- else
- print("Monitor not connected.")
- end
Advertisement
Comments
-
- made with chatgpt with minor tweaking to the source material, enjoy
Add Comment
Please, Sign In to add comment
Advertisement