This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Exerro's profile picture

stuck with rednet problem

Started by Exerro, 15 September 2012 - 09:05 AM
Exerro #1
Posted 15 September 2012 - 11:05 AM
hi, im making a facebook/skype type program with contacts and message sending and things but im already stuck on a receiving problem…it will receive a message when the program is running and should write the message into "messages/<id>/msgLog" but it doesnt. i tried to find where the problem was and there wasnt one (it ran through the whole code fine). the code is

function receive()
if text ~= nil then
  text = split(text, "-:-")
  if text[1] == "bluechat" then
   table.remove(text, 2)
   table.remove(text, 4)
   table.remove(text, 6)
   for i = 1,2 do
	if not fs.isDir("messages") then
	 fs.makeDir("messages")
	else
	 for k = 1,2 do
	  if not fs.isDir("messages/"..key) then
	   fs.makeDir("messages/"..key)
	  else
	   z = fs.open("messages/"..key.."/msgLog","a")
	   z.writeLine(text[1])
	   z.writeLine(text[2])
	   z.writeLine(text[3])
	   z.writeLine(text[4])
	   break
	  end
	 end
	 break
	end
   end
  else
   for i = 1,2 do
	if not fs.isDir("messages") then
	 fs.makeDir("messages")
	else
	 for k = 1,2 do
	  if not fs.isDir("messages/"..key) then
	   fs.makeDir("messages/"..key)
	  else
	   z = fs.open("messages/"..key.."/notBlueChatMsgs","a")
	   for m = 1,#text do
		z.writeLine(text[m])
	   end
	   break
	  end
	 end
	 break
	end
   end
  end
end
end
it does get to the bit where it writes the message but just doesnt write it into the file…pls help!

EDIT: the formatting is a bit messed up…sorry…
KaoS #2
Posted 15 September 2012 - 12:56 PM
after you have written to the file you must close it with z.close(), that is when it actually writes