• Error Opening files
    4 replies, posted
Hello, I'm trying to open a file ("garrysmod/models/player/newfile.mdl") which does not exist in order to write content (binary) to it, using following code: [CODE] function savePlayerModel(data, filename) filename = file.Open("models/player/" .. fileName, "wb", "GAME") filename:Write(data) filename:Flush() filename:Close() end[/CODE] file.Open(...) returns nil, even if I use an existing file. What am I doing wrong? Edit for future reference: The error was, that the file must be a .txt file AND it must be written in the data folder.
You can't write outside of the data directory.
So, if I would be using "r" as argument#2 file.Open() wouldn't return nil? And if I would write to the data directory it wouldn't return it either?
-I was just wrong in general, I just removed it-
I just modified the code in order to check it if it would be possible to write to the DATA folder: [CODE]function savePlayerModel(data, filename) print(filename) print(file.Exists("e2files", "DATA")) local modelFile = file.Open("e2files/" .. filename, "wb", "DATA") modelFile:Write(data) modelFile:Flush() modelFile:Close() end[/CODE] Output is: policeadm.mdl true And modelFile is still nil. So the error is not the folder and neither that "filename" is nil...
Sorry, you need to Log In to post a reply to this thread.