Page 1 of 1

game.write_file() not working?

Posted: Fri Jul 12, 2024 7:45 pm
by KrausesH
I tried to write the simplest test possible for this, but I can't get it to work. I just want to write something to a file. I checked the `script-output` folder (I'm on MacOS) but it stays empty. I thought it might be some issues with permission, but the `/screenshot` command from the console actually saves those in the same folder.


control.lua:

Code: Select all

script.on_init(function()
    game.print("Testing file write")
    game.write_file("minimal_test_log.txt", "File writing test\n", true, 0)
end)
documentation I used as reference: https://lua-api.factorio.com/latest/cla ... rite_file

Re: game.write_file() not working?

Posted: Fri Jul 12, 2024 8:16 pm
by Bilka
You set it to write only the file only on the headless server, but considering that you're using /screenshot to test that sounds like you're not running a headless server. Try leaving out the player_index argument.

Also, because this code is in on_init, make sure that you're starting a new save or adding the mod to the save for the first time.

Re: game.write_file() not working?

Posted: Fri Jul 12, 2024 8:23 pm
by KrausesH
You are my hero. It was indeed the player_index argument. Thanks a ton!