jekart021 Posted January 6, 2022 Share Posted January 6, 2022 (edited) I need custom logs for my personal needs. But when I try to write text to a file, I run into a problem, namely with an incorrectly specified path to the file. How could I fix this? I re-checked it several times, the path is correct, and the path to the mod folder contains spaces. P.S. This code was executed when the player received damage, just for testing. Comptere code: AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return end inst:ListenForEvent("attacked", function(inst) local inputFileName = "C://log.txt" local FileWrite FileWrite = G.io.open(inputFileName, "a") FileWrite:write("hello world") FileWrite:close() end) end) Main Code: local inputFileName = "C://log.txt" local FileWrite FileWrite = G.io.open(inputFileName, "a") FileWrite:write("hello world") FileWrite:close() Edited January 6, 2022 by jekart021 Link to comment https://forums.kleientertainment.com/forums/topic/136756-writing-text/ Share on other sites More sharing options...
Leonidas IV Posted January 6, 2022 Share Posted January 6, 2022 1 hour ago, jekart021 said: I need custom logs for my personal needs. But when I try to write text to a file, I run into a problem, namely with an incorrectly specified path to the file. How could I fix this? I re-checked it several times, the path is correct, and the path to the mod folder contains spaces. P.S. This code was executed when the player received damage, just for testing. Comptere code: AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return end inst:ListenForEvent("attacked", function(inst) local inputFileName = "C://log.txt" local FileWrite FileWrite = G.io.open(inputFileName, "a") FileWrite:write("hello world") FileWrite:close() end) end) Main Code: local inputFileName = "C://log.txt" local FileWrite FileWrite = G.io.open(inputFileName, "a") FileWrite:write("hello world") FileWrite:close() The default path for mods to create files is in C:\Program Files (x86)\Steam\steamapps\common\Don't Starve Together\data For example, if you put the path as "log.txt", the file will be created in the mentioned directory. You can "go back" from directories using "../", for example: "../mods/log.txt" will create a file in the mods folder. The "../" indicates that the mods are in the previous folder, in this case Dont Starve Together. So, I believe you can go back to the C:/ path like this. Link to comment https://forums.kleientertainment.com/forums/topic/136756-writing-text/#findComment-1531014 Share on other sites More sharing options...
jekart021 Posted January 6, 2022 Author Share Posted January 6, 2022 (edited) то есть если я напишу в папку с модом то C: \Program Files (x86)\Steam\steamapps\common\Don't Starve Together\data/mods/test/log.txt? нет. local inputFileName = "C:/Program Files (x86)/Steam/steamapps/common/Don't Starve Together/data/mods/Test/log.txt" oh, I'm stupid, thanks, I get what you mean. And it works Edited January 6, 2022 by jekart021 Link to comment https://forums.kleientertainment.com/forums/topic/136756-writing-text/#findComment-1531016 Share on other sites More sharing options...
jekart021 Posted January 6, 2022 Author Share Posted January 6, 2022 hmm, I ran into another problem. The text writes only 1 time and is no longer updated. local inputFileName = "../mods/log.txt" local FileWrite FileWrite = G.io.open(inputFileName, "r+") FileWrite:write(inst.name, G.os.date("%Y.%m.%d %H:%M\n")) FileWrite:close() end log.txt Link to comment https://forums.kleientertainment.com/forums/topic/136756-writing-text/#findComment-1531029 Share on other sites More sharing options...
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