Nightmare12 Posted June 26, 2012 Posted June 26, 2012 Hi, i have problem with fileGetSize and fileRead. I have this code: local str = fileRead( file, fileGetSize ( file ) or 0 ) And i have error Bad 'number' pointer @ 'fileRead'(2) Whats wrong with this?
MTA Team qaisjp Posted June 26, 2012 MTA Team Posted June 26, 2012 Hi, i have problem with fileGetSize and fileRead. I have this code: local str = fileRead( file, fileGetSize ( file ) or 0 ) And i have error Bad 'number' pointer @ 'fileRead'(2) Whats wrong with this? you are doing something wrong. the code looks fine to me
Nightmare12 Posted June 26, 2012 Author Posted June 26, 2012 -- load JSON from file function loadJSONData( filename ) local file = fileExists( filename ) and fileOpen( filename, true ) or fileCreate( filename ) local str = fileRead( file, fileGetSize( file ) or 0 ) local t = fromJSON( str ) or {resolution = {}} fileClose( file ) return t end It's all code of function
MTA Team qaisjp Posted June 26, 2012 MTA Team Posted June 26, 2012 -- load JSON from file function loadJSONData( filename ) local file = fileOpen( filename, true ) or fileCreate( filename ) local str = fileRead( file, fileGetSize( file ) or 0 ) local t = fromJSON( str ) or {resolution = {}} fileClose( file ) return t end
Nightmare12 Posted June 26, 2012 Author Posted June 26, 2012 Thanks, it work But what was make this issue? I want to now for the future
MTA Team qaisjp Posted June 26, 2012 MTA Team Posted June 26, 2012 local file = fileExists( filename ) and fileOpen( filename, true ) or fileCreate( filename ) I'm not sure, I'm assuming that if the file already existed, you would get a TRUE value, and not a file element. You could also fix it by using parentheses
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now