Debugging utilities built in to Factorio
Debugging utilities built in to Factorio
I'm wondering what debugging modules are built into Factorio. I know about game.player.print. Are there any other facilities? For example, there are pretty printers that will print tables to strings. Is such a printer built into Factorio?
Also, are there any better alternatives than the game console? For example, a window that can persist over gameplay?
Also, are there any better alternatives than the game console? For example, a window that can persist over gameplay?
Re: Debugging utilities built in to Factorio
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 )) ).
There is serpent pretty printer, which can print lua tables ( syntax is print( serpent.block( arg )) ).
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Debugging utilities built in to Factorio
Another useful function is debug.traceback() to figure out how the hell you ended up somewhere.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Debugging utilities built in to Factorio
This is great, thanks. So I can put the game in windowed mode and look at the terminal rather than having to use the in-game console for debugging. Fantastic.Adil wrote: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 )) ).
Is there any hot-swapping of mod code?
Re: Debugging utilities built in to Factorio
control.lua is reloaded with loading save or map restart. data.lua is only reloaded on game restart.obstinate wrote: Is there any hot-swapping of mod code?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Debugging utilities built in to Factorio
How do I exactly run Factorio from the console using Windows? Just running will start the game, but return immediately so I don't see any output. Running it using doesn't start the game at all. Redirecting output to a file like doesn't help, as the file remains empty.
Code: Select all
factorio.exe
Code: Select all
start factorio.exe /wait
Code: Select all
factorio.exe > log.txt
Re: Debugging utilities built in to Factorio
Is that using Steam? Try the DRM free version, that should stay attached to the terminal.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Debugging utilities built in to Factorio
I should have figured Steam was the problem
The direct downloaded version does show me the output, including serpent-ed tables. Thanks!
The direct downloaded version does show me the output, including serpent-ed tables. Thanks!
-
- Burner Inserter
- Posts: 6
- Joined: Sat Oct 01, 2016 11:01 am
- Contact:
Re: Debugging utilities built in to Factorio
Just in case someone finds this through Google...
It's possible to keep using the Steam version and still have a console.
Use "SET LAUNCH OPTIONS..." from Factorio's properties in Steam and set them to:
It's possible to keep using the Steam version and still have a console.
Use "SET LAUNCH OPTIONS..." from Factorio's properties in Steam and set them to:
Code: Select all
cmd /c %command%
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Debugging utilities built in to Factorio
Don't forget the `log()` function available to lua throughout the entire script lifecycle - dumps stuff to game log. It takes single argument (as far as I know) - a string.
For example, in data-final-fixes.lua:
Serpent docs: https://github.com/pkulchenko/serpent
For example, in data-final-fixes.lua:
Code: Select all
log( serpent.block( data.raw, {comment = false, numformat = '%1.8g' } ) )
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Debugging utilities built in to Factorio
so eeuhm, I'm using serpent.dump, to help check my data integrity, but all my ouptuts looks like this:aubergine18 wrote:Don't forget the `log()` function available to lua throughout the entire script lifecycle - dumps stuff to game log. It takes single argument (as far as I know) - a string.
For example, in data-final-fixes.lua:
Serpent docs: https://github.com/pkulchenko/serpentCode: Select all
log( serpent.block( data.raw, {comment = false, numformat = '%1.8g' } ) )
Code: Select all
do local _={[1]={name="teamname",players={}}};return _;end
is this also the case for you, or am I seeing a bug?
EDIT: the grammar made sense in dutch...
Last edited by matjojo on Fri Oct 07, 2016 7:33 pm, edited 1 time in total.
Re: Debugging utilities built in to Factorio
Try serpent.block() instead of serpent.dump().
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Debugging utilities built in to Factorio
serpent.block() does not have the 'do local' part in front and behind it, but it has the added problem that it is designed to not show tables in tables, which I need it to doprg wrote:Try serpent.block() instead of serpent.dump().
Re: Debugging utilities built in to Factorio
Huh?matjojo wrote:serpent.block() does not have the 'do local' part in front and behind it, but it has the added problem that it is designed to not show tables in tables, which I need it to do
Code: Select all
/c print(serpent.block({1,2,{3,4,{5,6}}}))
Code: Select all
{
1,
2,
{
3,
4,
{
5,
6
} --[[table: 0x7f12d8873aa0]]
} --[[table: 0x7f12d8873a40]]
} --[[table: 0x7f12d88739e0]]
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Debugging utilities built in to Factorio
Here's what I use
Example: In my data.lua, I logged `data.raw` to get this: https://raw.githubusercontent.com/auber ... r/data.raw
Code: Select all
local logFormat = {comment = false, numformat = '%1.8g' }
log( serpent.block( someObject, logFormat ) )
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Debugging utilities built in to Factorio
prg wrote:Huh?matjojo wrote:serpent.block() does not have the 'do local' part in front and behind it, but it has the added problem that it is designed to not show tables in tables, which I need it to do
Code: Select all
/c print(serpent.block({1,2,{3,4,{5,6}}}))
Code: Select all
{ 1, 2, { 3, 4, { 5, 6 } --[[table: 0x7f12d8873aa0]] } --[[table: 0x7f12d8873a40]] } --[[table: 0x7f12d88739e0]]
yeah, I'm sorry. the table in the table I used was empty, I forgot -_-