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

file.write not working

Started by The Penguin21, 06 September 2017 - 12:54 PM
The Penguin21 #1
Posted 06 September 2017 - 02:54 PM
Ok so I was trying to create a remote control program, but it ain't working.
So first i typed in
 local file fs.open("tempfile", "w") 
and after that
 file.write("message") 
but it outputs an error:
 attempt to index ? (a nil value) 
KingofGamesYami #2
Posted 06 September 2017 - 03:00 PM
If you're doing this in the lua prompt, that's because the scope of each new line is different. So your file variable doesn't exist after you press "enter".
The Penguin21 #3
Posted 06 September 2017 - 03:07 PM

local file fs.open("tempfile", "w")
file.write("message")
file.close()
This is the code i got so far, its in a file, but it wont seem to work neither
KingofGamesYami #4
Posted 06 September 2017 - 03:11 PM
You've forgotten to use the assignment operator.

local file = fs.open( "tempfile", "w" )