So i’m trying to read a number in a file and then save that number to a variable. I’m doing this through a module. When i do this locally it works. If through a module then it doesn’t.
Here is how i do it locally.
local number \_path = system.pathForFile( "digit.txt", system.DocumentsDirectory ) \_file = io.open( \_path, "r" ) for line in \_file:lines() do number = tonumber(line) end io.close( \_file ) \_file = nil \_path = nil print(number)
This works and prints this number in that file.
Now below i will have the module way. { NOTE - I did require everything correctly and all }
mod.lua –
function M.readFile( \_fileName, \_number ) local \_number \_path = system.pathForFile( \_fileName, system.DocumentsDirectory ) \_file = io.open( \_path, "r" ) for line in \_file:lines() do \_number = tonumber(line) end io.close( \_file ) \_file = nil \_path = nil end
readIt.lua –
local number Z.readFile( "digit.txt", number ) print(number)
So why isn’t it adding the number to “local number”? It just prints “nil”.
Thanks!
–SonicX278