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

Some prob with writing something in a file

Started by Bobibibi, 29 June 2015 - 04:19 PM
Bobibibi #1
Posted 29 June 2015 - 06:19 PM
Hey everybody!

Here my prob:


When I'm trying to write something in a file,nothing happen. I'm probably doing something bad but I don't know what is it.

Here is the code:

local modem = peripheral.wrap("back")

modem.open(10)

event,side,frequency,replyFrequency, message, distance = os.pullEvent("modem_message")

fs.open("here","w").write(textutils.unserialise(message))
--message is a string value after being unserialise

thanks for your help!

Ps:Give me some feedback on my spelling and writing. English is not my maternal language and I have some difficulties with it.
Creator #2
Posted 29 June 2015 - 06:43 PM
You'll want to do it this way:

file = fs.open("here","w")
file.write("stuff")
file.close()

You need to close the file in order to tell ComputerCraft/Java/Windows to actually save the file and free it so other programs can edit it.

And unserialize returns a table, so there is no way for it to be a string.
Edited on 29 June 2015 - 04:44 PM
Bobibibi #3
Posted 29 June 2015 - 06:49 PM
thx dude
sorry for my noobism ^^
Creator #4
Posted 29 June 2015 - 07:09 PM
Oh that is OK. I was like this some months ago.
MKlegoman357 #5
Posted 29 June 2015 - 07:50 PM
And unserialize returns a table, so there is no way for it to be a string.

It returns whatever serialized data you gave it. The way it currently is setup and depending on the serialized data it may return these types: nil, number, boolean, string, table, function. textutils.serialize can only serialize these types (note that it's not only tables!): nil, boolean, number, string, table (non-recursive only).