i'm very new to lua scripting, i'm starting with create and write text to file by Lua with this script:
A = "Hello"
local file = io.open ('test.txt',"w")
file:write(A)
file:close()
And I got this error:
:3 Attempt to index local 'file' (a nil value)
What's wrong here?
P/s: I'm running this lua on camera with CHDK.
io.open will return nil if it was unable to open the file. You can retrieve the error message:
A = "Hello"
local file, err = io.open ('test.txt',"w")
if file==nil then
print("Couldn't open file: "..err)
else
file:write(A)
file:close()
end
See: http://www.lua.org/pil/21.2.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With