I am trying to make program that allows user to write messages,save them and show later, but I'm getting an error:startup:19: attemt to call a string (19 line is print("message "..message)
But I just can't get that right, I have red("I don't know if that's a verb because I don't know English that well.") the wiki and tutorials in this forums, but still I can't get it right.
And could you please show me how to make computer detect if there is message or not, because if there is no message then I want computer to say that to user(I tried fs.exists, but can't figure it out either.).
Spoiler
Sorry, for posting full code, but else you wouldn't understand what I'm trying to do, but I removed some parts of it to make it shorter.
id = os.computerID()
pass = "gta"
function checkm() --Here computer opens and prints the message (I think here is the mistake)
term.restore()
file = fs.open("messages/message","r")
local text = {}
local print = file.readLine()
repeat
table.insert(text,print)
line = file.readLine()
until line == nil
file.close()
local message = text[1]
term.clear()
term.setCursorPos(1,1)
print("Message "..message) --19 line with the error.
end
function message() --Here user writes the message which gets saved into the computer.This seems to work fine, because everything gets really saved.
term.clear()
term.setCursorPos(1,1)
print("Monitor can't work, while accessing computer.")
term.restore()
term.clear()
term.setCursorPos(1,1)
fs.makeDir("messages")
print("Enter your message")
write("Text:")
local text = read()
local file = fs.open("messages/message","w")
file.writeLine(text)
file.close()
term.clear()
term.setCursorPos(1,1)
print("Message written")
end
mon = peripheral.wrap("left")
term.redirect(mon)
term.clear()
term.setCursorPos(1,1)
while true do
local time = os.time()
time = textutils.formatTime(time, true)
print[[
1.Access Computer.
2.Shutdown.
3.Leave a message.
4.Check messages.]]
term.setCursorPos(1,10) print("Computer ID:"..id.."") term.setCursorPos(26,10) print("Time "..time)
os.startTimer(0.5) event, param1, param2 = os.pullEvent() if event == "char" and param1 == "1" then access() elseif event == "char" and param1 == "2" then shutdown() elseif event == "char" and param1 == "3" then message() elseif event == "char" and param1 == "4" then checkm() end
term.clear()
term.setCursorPos(1,1)
end
If you need more details, just ask.
Thank you.