Posted 08 September 2012 - 06:35 AM
hi everyone
i've made a program that allowes you to send a rednet mail to 1 host computer.
and the host computer saves the messages,
but at the end of the messages i get a random number does any1 know what causes it?
message sender
message host
i've made a program that allowes you to send a rednet mail to 1 host computer.
and the host computer saves the messages,
but at the end of the messages i get a random number does any1 know what causes it?
message sender
os.pullEvent = os.pullEventRaw
--config
menuname = "informationdesk"
programname = "startup"
updatername = "updater"
updaterpass = "hello"
shellpass = "peanut"
host = 6
function clear()
term.clear()
term.setCursorPos(1, 1)
end
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
-- Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write(menuname)
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "OPTION 1" )
elseif nOption == 2 then
term.write( "OPTION 2" )
else
term.write( "OPTION 3" )
end
end
-- Display the frontend
term.clear()
local function drawFrontend()
clear()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "SELECT AN OPTION" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Send message ]") or "Send message" )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Main menu ]") or "Main menu" )
printCentred( math.floor(h/2) + 2, "" )
end
drawMenu()
drawFrontend()
while true do
drawMenu()
drawFrontend()
local e,p = os.pullEventRaw()
if e == "key" then
local key = p
if key == 17 or key == 200 then
-- Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
-- Down
if nOption < 2 then -- Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
-- Enter
break
end
end
end
-- Conditions
if nOption == 1 then
clear()
print("enter your name")
name = read()
print("enter your message")
msg = read()
msg2 = " "..msg
rednet.send(host, name..msg2)
shell.run(programname)
else
clear()
shell.run(programname)
end
message host
rednet.open("top")
filename = "messages"
term.clear()
term.setCursorPos(1, 5)
print(" X==---==X")
print(" X mails X")
print(" X==---==X")
local h = fs.open(filename, "r")
repeat
local line = h:readLine()
print(line)
until not line
h:close()
term.setCursorPos(1, 1)
print("X==--------------==X")
print("X looking for mail X")
print("X==--------------==X")
id, name, msg = rednet.receive()
file = fs.open("messages", "a")
file.writeLine(id.." "..name.." "..msg)
file.close()
os.reboot()