Here's the message submitter code:
--Setting up the screen
local ver = "1.0.1"
rednet.open("back")
function start()
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.yellow)
print("Message Board V."..ver)
term.setTextColor(colors.white)
end
start()
--Actual code starts...
--now:
function getInfo()
term.write("Please enter your username: ")
usr = read()
print("Enter your message (use only one line)(write 'delete' to delete the message you posted):")
message = read()
end
function fill()
msg = nil
local id, msg, dist = rednet.receive(15)
if msg == nil then
term.setTextColor(colors.red)
print("Error! Please tell Austin or Panda!")
sleep(10)
os.reboot()
end
end
function msgSend()
rednet.broadcast("start")
local id, msg, dist = rednet.receive(15)
if msg == "go on" then
rednet.broadcast("user")
fill()
rednet.broadcast(usr)
fill()
rednet.broadcast("message")
fill()
rednet.broadcast(message)
fill()
rednet.broadcast("end")
else
term.setTextColor(colors.red)
print("Error! Please tell Austin or Panda!")
sleep(10)
os.reboot()
end
os.reboot()
end
getInfo()
msgSend()
Here's the Message board code:rednet.open("bottom")
--ease of use function ftw!
function reply(text)
rednet.broadcast(text)
end
function rec(timeout)
if timeout == nil then
id, msg, d = rednet.receive()
else
id, msg, d = rednet.receive(timeout)
end
print("Message received!")
end
--Real code now;
function loadFile()
local check = fs.exists("messages")
if check == true then
shell.run("messages")
else
saveFile(true)
end
end
function saveFile(gen)
if gen == nil then
w = fs.open("messages", "a")
w.writeLine("center("..[["]]..MESSAGE..[["]]..")")
w.writeLine("p.setTextColor(colors.yellow)")
w.writeLine("center("..[["]].."-"..USER..[["]]..")")
w.writeLine("p.setTextColor(colors.white)")
w.close()
os.reboot()
else
w = fs.open("messages", "w")
w.writeLine("p = peripheral.wrap("..[["]].."top"..[["]]..")")
w.writeLine("p.setTextScale(1)")
w.writeLine("p.clear()")
w.writeLine("p.setCursorPos(1,1)")
w.writeLine("function center(text)")
w.writeLine("local x, y = p.getSize()")
w.writeLine("local x2, y2 = p.getCursorPos()")
w.writeLine("p.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)")
w.writeLine("p.write(text)")
w.writeLine("y2 = y2 + 1")
w.writeLine("p.setCursorPos(1, y2)")
w.writeLine("end")
w.writeLine("p.setTextColor(colors.orange)")
w.writeLine("center("..[["]].."Server Message Board"..[["]]..")")
w.writeLine("local x, y = p.getSize()")
w.writeLine("for i = 1, x do")
w.writeLine("p.write("..[["]].."~"..[["]]..")")
w.writeLine("end")
w.writeLine("p.setCursorPos(1, 3)")
w.writeLine("p.setTextColor(colors.white)")
w.close()
os.reboot()
end
end
function re()
rec()
if msg == "start" then
reply("go on")
id, mssg, d = rednet.receive(15)
if mssg == "user" then
reply(".")
id, USER, d = rednet.receive(15)
reply(".")
elseif mssg == "message" then
reply(".")
id, MESSAGE, d = rednet.receive(15)
reply(".")
elseif mssg == "end" then
saveFile()
end
else
os.reboot()
end
end
loadFile()
re()
When i submit a message, it is received by the board, but it doesn't actually write it on the save file, and therefore it doesn't display the messages. And it just quits.
Edited by austinv11, 30 January 2014 - 10:40 AM.












