I'm writing a Factorio mod, and I'm trying to figure out why it doesn't work. Can I do some kind of error / debug logging somewhere? Both manual (printing variables) and simple error reporting (accessing a property that doesn't exist) would be great. I know about the player.print method, but I can only get it to print string literals, not objects:

script.on_event(defines.events.on_player_created, function(event)
        local player = game.get_player(event.player_index)
        player.print("Hi player") -- works
        player.print(player) -- does not work. Any error message would be nice

I've also tried the log file in the application folder, and the various debug modes (F5/F6 in game), but so far haven't found anything useful.

  • \$\begingroup\$ Perhaps you're assuming it will automatically generate a string from the object? You might need to create and explicitly use some kind of ToString() method. \$\endgroup\$ – MichaelHouse May 1 '16 at 20:47

According to this forum post

You can launch the game from console, so standard print function would send its output there. You can redirect that output to files.

There is serpent pretty printer, which can print lua tables - syntax is print(serpent.block(arg)).

  • 1
    \$\begingroup\$ Sounds good, but it doesn't quite work. Running factorio.exe from the command prompt starts the game, but returns immediately and I only see the output of the first log line. Using start factorio.exe /wait doesn't work either, because it only opens a console window and doesn't start the game at all. \$\endgroup\$ – Jorn May 1 '16 at 19:03

You can use the error() function which sends to factorio-current.log

For example:

error("Hi player")



  • \$\begingroup\$ serpent_block --> serpent.block \$\endgroup\$ – Tony Baguette Feb 12 '19 at 19:45
  • \$\begingroup\$ It actually shows an "error" popup with the message at the game loading and prevents the mod to be loaded. \$\endgroup\$ – Tony Baguette Feb 12 '19 at 19:47

There is a write_file method in LuaGameScript.

game.write_file("mylog.log", serpent_block(table_name)) -- normal write
game.write_file("mylog.log", serpent_block(table_name), true) -- appending


The file will end up in a folder called script-output under %APPDATA%/Factorio, next to your scenarios folder.

  • 1
    \$\begingroup\$ Does not seem to work from data.lua \$\endgroup\$ – LOST Aug 28 '17 at 0:25
  • 1
    \$\begingroup\$ data.lua is not a normal runtime script. Its purpose is to describe a data structure and nothing else. Most(all?) runtime objects are not accessible during it's interpretation. In particular the global LuaGameScript object called game does not even exist then. \$\endgroup\$ – Martin Lütke Sep 3 '17 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.