10 posts
Posted 26 May 2014 - 10:21 AM
I'm stumped, how do I go about writing a binary file? All I get is an empty file with this code:
f = fs.open("file", "wb")
f:write(71)
f:write(79)
f:close()
print(fs.getSize"file")
Outputs: 0
7508 posts
Location
Australia
Posted 26 May 2014 - 10:43 AM
firstly fs uses dot notation not colon syntax, so you should be
local f = fs.open("file", "wb")
f.write(71)
f.write(79)
f.close()
print(fs.getSize("file"))
however that code works perfectly fine for me, outputting the file size of 512 (which is kinda incorrect, read the opening paragraph
here). What version of ComputerCraft are you using? are you using an emulator?
10 posts
Posted 26 May 2014 - 06:13 PM
firstly fs uses dot notation not colon syntax, so you should be
local f = fs.open("file", "wb")
f.write(71)
f.write(79)
f.close()
print(fs.getSize("file"))
however that code works perfectly fine for me, outputting the file size of 512 (which is kinda incorrect, read the opening paragraph
here). What version of ComputerCraft are you using? are you using an emulator?
I'm on ComputerCraft 1.63, no other mods. Indeed, the dot syntax works, and the program now prints 2, though contrary to what the wiki says.
Edited on 26 May 2014 - 04:14 PM
1140 posts
Location
Kaunas, Lithuania
Posted 26 May 2014 - 08:41 PM
I'm on ComputerCraft 1.63, no other mods. Indeed, the dot syntax works, and the program now prints 2, though contrary to what the wiki says.
Where have you read that you need to use colon notation instead of dot notation on handles returned by fs.open? io.open returns a handle which uses colon notation.
570 posts
Posted 26 May 2014 - 09:15 PM
and the program now prints 2, though contrary to what the wiki says.
Are you using an emulator? Because some emulators might output the file size correctly.
10 posts
Posted 26 May 2014 - 09:40 PM
I'm on ComputerCraft 1.63, no other mods. Indeed, the dot syntax works, and the program now prints 2, though contrary to what the wiki says.
Where have you read that you need to use colon notation instead of dot notation on handles returned by fs.open? io.open returns a handle which uses colon notation.
Nowhere, I was indeed getting confused with io.open. I understand it now, I haven't used the fs api too much.
and the program now prints 2, though contrary to what the wiki says.
Are you using an emulator? Because some emulators might output the file size correctly.
No emulator, Vanilla Minecraft 1.6.4 with ComputerCraft 1.63, absolutely no other mods.
7508 posts
Location
Australia
Posted 27 May 2014 - 01:42 AM
and the program now prints 2, though contrary to what the wiki says.
Are you using an emulator? Because some emulators might output the file size correctly.
No emulator, Vanilla Minecraft 1.6.4 with ComputerCraft 1.63, absolutely no other mods.
perhaps dan200 has finally fixed that 'bug'