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

Extra Work

Started by candycool1234, 22 July 2013 - 07:12 PM
candycool1234 #1
Posted 22 July 2013 - 09:12 PM
I'm making a program using misc craft chat boxes and so far it will print what's said in chat but now I would like to record it is there any way and btw flopped and chunk loaders are available code is

For x = 1, 100 do
Record = peripheralwrap("left")
Dg,room,ice = os.pullEvent("chat")
Print("Dg")
Print("room")
Print("ice")
End
candycool1234 #2
Posted 22 July 2013 - 09:15 PM
Floppy sorry iPhone auto correct
Grim Reaper #3
Posted 23 July 2013 - 03:07 AM
You could store all of the messages in some table.


local messages = {}

for x = 1, 100 do
  record = peripheral.wrap ("left")
  dg, room, ice = os.pullEvent ("chat")

  table.insert (messages, { dg = dg, room = room, ice = ice })
end
KaoS #4
Posted 23 July 2013 - 08:47 AM
if you put quotes around your variables you are gonna have a bad time :mellow:/> and by that I mean get strings instead
candycool1234 #5
Posted 23 July 2013 - 11:23 AM
That's helpful yet did not awnser my question of how do I save what is recorded
KaoS #6
Posted 23 July 2013 - 11:34 AM
is Grim Reaper's post unclear? I think it explains how to store the data. If you don't understand any of it feel free to ask. You may need help accessing the record once you have stored the data if you aren't familiar with tables
PixelToast #7
Posted 23 July 2013 - 11:48 AM
this is what you want, grim didn't understand what you were trying to do

local event,player,message
while true do
	event,player,message=os.pullEvent("chat")
	print("<"..player.."> "..message)
end
extra bit, you can save it to a file:

local file,event,player,message,line=fs.open("chatlog","a+")
while true do
	event,player,message=os.pullEventRaw()
	if event=="chat" then
		line="<"..player.."> "..message
		print(line)
		file.write(line)
	elseif event=="terminate" then
		file.close()
		break
	end
end
KaoS #8
Posted 23 July 2013 - 12:09 PM
sorry for being that irritating perfectionist dude but you should just flush the file every write to avoid losing your changes to shutdowns and restarts
candycool1234 #9
Posted 23 July 2013 - 03:06 PM
Thank you sorry didn't mean to have you guys do all the work but thank you very much
candycool1234 #10
Posted 23 July 2013 - 03:07 PM
Also is there a way I can have it count up the save number so it does not over right
albrat #11
Posted 23 July 2013 - 04:38 PM
That saving system is on append mode, so every new line is appended to the end of the file.
this is what you want, grim didn't understand what you were trying to do

local event,player,message
while true do
	event,player,message=os.pullEvent("chat")
	print("<"..player.."> "..message)
end
extra bit, you can save it to a file:

local file,event,player,message,line=fs.open("chatlog","a+")
while true do
	event,player,message=os.pullEventRaw()
	if event=="chat" then
		line="<"..player.."> "..message
		print(line)
		file.write(line)
	    file.flush()
	elseif event=="terminate" then
		file.close()
		break
	end
end
candycool1234 #12
Posted 23 July 2013 - 08:11 PM
It has no error yet it's not saving
PixelToast #13
Posted 23 July 2013 - 11:39 PM
strange, i might have used it wrong one min while i test

edit:

local file,event,player,message,line=fs.open("chatlog","a")
while true do
	    event,player,message=os.pullEventRaw()
	    if event=="chat" then
			    line="<"..player.."> "..message
			    print(line)
			    file.write(line)
	    elseif event=="terminate" then
			    file.close()
			    break
	    end
end
apparently it was a and not a+
it sould work now
sorry for being that irritating perfectionist dude but you should just flush the file every write to avoid losing your changes to shutdowns and restarts
nah, append mode flushes automatically when its rebooted (well ctrl-r atleast, it sould work when unloading chunks)
theoriginalbit #14
Posted 24 July 2013 - 12:28 AM
it sould work when unloading chunks
I haven't had it work yet.
Lyqyd #15
Posted 24 July 2013 - 01:38 AM
Don't count on files getting flushed/closed correctly during unloads, it's not reliable. Open the file when you want to write to it, and close it when you're done. Even if it happens a lot.
PixelToast #16
Posted 24 July 2013 - 10:33 AM
Don't count on files getting flushed/closed correctly during unloads, it's not reliable. Open the file when you want to write to it, and close it when you're done. Even if it happens a lot.
you dont have to close it, just flush it to ensure the data is always written to the file
Lyqyd #17
Posted 24 July 2013 - 10:42 AM
Flush isn't an available method inside ComputerCraft unless it was added in a recent update.
theoriginalbit #18
Posted 24 July 2013 - 10:46 AM
yeh it was added in about 3 updates ago, or so… I didn't know until Cloudy corrected me on the matter a few months ago… still waiting for seek! xD
albrat #19
Posted 24 July 2013 - 11:47 AM
I did have to go searching to check but it's in Lua and CC actually works with flushing the file. (took about 30 minutes of google and lua manual searches)… I checked that it existed first :P/> then checked the command in CC.. Think it has been in a while, my CC version is quite old (1.4.7 minecraft)…

I really need to get my server admin to update to the newest version. lol. (custom build with 97 mods).
theoriginalbit #20
Posted 24 July 2013 - 10:33 PM
I did have to go searching to check but it's in Lua and CC actually works with flushing the file. (took about 30 minutes of google and lua manual searches)… I checked that it existed first :P/> then checked the command in CC…

Quickest way to check

CraftOS <version>
> lua
Interactive Lua prompt.
Call ext() to exit.
lua> local h = fs.open("somefile", "w") for k,v in pairs(h) do print(k,":",v) end
close: function: <memory address>
write: function: <memory address>
flush: function: <memory address>
writeLine: function: <memory address>
candycool1234 #21
Posted 25 July 2013 - 02:58 PM
Thx but km on a old version so I just need to add a press any button to stop recording
candycool1234 #22
Posted 27 July 2013 - 04:12 PM
Jw where is it saving?