130 posts
Location
Here
Posted 07 March 2016 - 12:46 AM
I'm not a retard, why isn't this working?
ANSWER
--Lua console localizes variables to the line of the prompt. Exclude keyword 'local'
file = fs.open('filename','w')
file.write('line')
file.close()
Edited on 07 March 2016 - 01:29 AM
7083 posts
Location
Tasmania (AU)
Posted 07 March 2016 - 12:50 AM
fs.open() is returning nil. This means that either the file "filename" is already locked open by another process (rebooting your real computer should sort that out), or the ComputerCraft computer's hard drive is full (removing files should sort that, though rarely you'll need to restart the Minecraft server as well - check what fs.getFreeSpace("") tells you).
130 posts
Location
Here
Posted 07 March 2016 - 12:55 AM
rebooted in game computer, and physical computer. Same error
fs.getFreeSpace('disk')
124000
Edited on 06 March 2016 - 11:56 PM
7083 posts
Location
Tasmania (AU)
Posted 07 March 2016 - 01:17 AM
Your screenshot doesn't show you attempting to write to "disk"…
130 posts
Location
Here
Posted 07 March 2016 - 01:36 AM
8543 posts
Posted 07 March 2016 - 01:37 AM
fs.open uses absolute paths.
130 posts
Location
Here
Posted 07 March 2016 - 01:38 AM
so begin at '/' ?
/disk/file
or begin at 'disk' ?
disk/file
8543 posts
Posted 07 March 2016 - 01:39 AM
In ComputerCraft, the leading slash is optional. Functions that require absolute paths will see /disk/file and disk/file as the same.
130 posts
Location
Here
Posted 07 March 2016 - 01:41 AM
In ComputerCraft, the leading slash is optional. Functions that require absolute paths will see /disk/file and disk/file as the same.
tried both
Edited on 07 March 2016 - 12:43 AM
7083 posts
Location
Tasmania (AU)
Posted 07 March 2016 - 01:52 AM
Hah, you're localising "file". The Lua console localises to the line, so you discard the handle the moment you create it.
130 posts
Location
Here
Posted 07 March 2016 - 01:57 AM
so, when i'm doing this in code i need to also keep it a non-localized variable? seems like a bug to me
7083 posts
Location
Tasmania (AU)
Posted 07 March 2016 - 02:17 AM
No, that's just a quirk of the Lua console - every command you put in gets its own scope. If you run that same code within a dedicated script file, then that ceases to be a problem.
Edited on 07 March 2016 - 01:18 AM
130 posts
Location
Here
Posted 07 March 2016 - 02:23 AM
ok, gotcha. Thanks :)/>