Jump to content

Recommended Posts

    
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()

image.png

image.png

unknown.png

image.png

image.png

image.png

image.png

Edited by jekart021
Link to comment
https://forums.kleientertainment.com/forums/topic/136756-writing-text/
Share on other sites

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()

image.png

image.png

unknown.png

image.png

image.png

image.png

image.png

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.

то есть  если я напишу в папку с модом то

 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"
image.png.72b4a20a24bc09966a969650e9bab2bf.png
oh, I'm stupid, thanks, I get what you mean.
And it works
Edited by jekart021
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...