• Problem with file.Read()
    7 replies, posted
Hi guys, I try to update one of my scripts with file.Read function but I don't know why, it doesn't find the file in my addons/data folder :/ I use : file.Read("motd.txt","DATA") but it returns nil I read that : [url]https://docs.google.com/document/d/1CIMxhvD7UX1lJPGi_DpDmPdTcVloIDYo-6AAMQl_KCs[/url] Someone can help me to fix this ? Thank you in advance.
It doesn't search in addons/data, it looks into garrysmod/garrysmod/data, even creating data folder in your addon won't make the engine look into it instead of the default data folder. Also putting "DATA" as an argument will make it start your search in the path I've specified up there, so now you'll have to either specify a path to file or just a file if it's not in a folder
How can I specify my addon data folder ? I need just something which tell me how :P
[LUA]file.Read("addon/MYADDON/data/motd.txt", "GAME")[/LUA] OR Setup a script in your addon to copy the file into the garrysmod/data folder.
Ok, I see. Thank you !
I want to know if it's possible to know in lua the addon folder where the lua file runs ?
Up ?
You shouldn't be reading through the addons folder directly like that as the user can name it anything they want, all legacy addons are included in the "GAME" path though (type "path" in console to list all of them) so you can just do [code]file.Read( "data/whatever.txt", "GAME" )[/code] and it should find it. edit: normally you would just be able to use the "DATA" path but I think it's been a little screwy with legacy addons so probably better to just do what I posted above... and make sure you use a unique filename
Sorry, you need to Log In to post a reply to this thread.