game.write_file() not working?

Place to get help with not working mods / modding interface.
Post Reply
KrausesH
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Jul 12, 2024 6:52 pm
Contact:

game.write_file() not working?

Post 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

Bilka
Factorio Staff
Factorio Staff
Posts: 3218
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: game.write_file() not working?

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

KrausesH
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Jul 12, 2024 6:52 pm
Contact:

Re: game.write_file() not working?

Post by KrausesH »

You are my hero. It was indeed the player_index argument. Thanks a ton!

Post Reply

Return to “Modding help”