91 posts
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
91 posts
Posted 22 July 2013 - 09:15 PM
Floppy sorry iPhone auto correct
504 posts
Location
Seattle, WA
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
1548 posts
Location
That dark shadow under your bed...
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
91 posts
Posted 23 July 2013 - 11:23 AM
That's helpful yet did not awnser my question of how do I save what is recorded
1548 posts
Location
That dark shadow under your bed...
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
2217 posts
Location
3232235883
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
1548 posts
Location
That dark shadow under your bed...
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
91 posts
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
91 posts
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
159 posts
Location
A Chair
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
91 posts
Posted 23 July 2013 - 08:11 PM
It has no error yet it's not saving
2217 posts
Location
3232235883
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)
7508 posts
Location
Australia
Posted 24 July 2013 - 12:28 AM
it sould work when unloading chunks
I haven't had it work yet.
8543 posts
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.
2217 posts
Location
3232235883
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
8543 posts
Posted 24 July 2013 - 10:42 AM
Flush isn't an available method inside ComputerCraft unless it was added in a recent update.
7508 posts
Location
Australia
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
159 posts
Location
A Chair
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).
7508 posts
Location
Australia
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>
91 posts
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
91 posts
Posted 27 July 2013 - 04:12 PM
Jw where is it saving?