Page 1 of 1

Modding Development Best Practices

Posted: Mon Aug 05, 2013 2:44 am
by otsukarci
I recently started experimenting with modding but wasn't able to setup an ideal development environment.

Is there a guide somewhere on this topic? If not can we please discuss best practices for modding development here so newbies can set up a development env. that makes mode developments easy?

Here are my development steps:

1- Open my IDE.
2- Write some code
3- Press 'Run' which deploys my code as a mode and then opens Factorio.
4- Play -> Load game -> (Find my save game and start)
5- Do some stuff, use in-game console for debugging to some degree.
6- Go to 2

I quit and launch game often to see my progress in small increments. I would like to merge step 3-4 so when my 'Run' script opens Factorio I can load my 'development' save automatically. Is there a way yo do this?

Is there any way to print debug logs other than using 'print' statements?

I think there will be more questions as I get experienced and try new things. For example managing and including lua dependencies.

Re: Modding Development Best Practices

Posted: Mon Aug 05, 2013 4:12 am
by zer0t3ch
otsukarci wrote:Is there any way to print debug logs other than using 'print' statements?
Is there any reason to use anything else? Also, I think the generic "print("text")" doesn't always work correctly, so get into the habit of using this:

Code: Select all

game.player.print("text")
otsukarci wrote:I would like to merge step 3-4 so when my 'Run' script opens Factorio I can load my 'development' save automatically. Is there a way yo do this?
I don't belive that this exists yet, but you could ask the devs to add an argument that can do that, which would theoretically make it possible to automate that.

Example: In Command Prompt* you would run something like this.

Code: Select all

"factorio.exe" -load=dev

* - Or a batch file

Re: Modding Development Best Practices

Posted: Mon Aug 05, 2013 7:04 am
by otsukarci
zer0t3ch wrote:
otsukarci wrote:Is there any way to print debug logs other than using 'print' statements?
Is there any reason to use anything else? Also, I think the generic "print("text")" doesn't always work correctly, so get into the habit of using this:

Code: Select all

game.player.print("text")
Sorry, I meant "game.player.print('text')" by "'print' statement". Since this method is already being used in the game (although not often), I looked for another way that can be used only for logging purposes. This is not really a big deal.

Will ask the devs about launching a saved game.

Re: Modding Development Best Practices

Posted: Mon Aug 05, 2013 7:26 am
by drs9999
Actually I do it in the same way than you do.

+ I normally add a giveItems function to the onInit event, so you have all the items that have to be tested or needed for testing on start.
+ I use game.player.print in the code for debug messages (only if I want to check one or two values)

You can also use game.showmessagedialog(variable), that opens a messagewindow like the one you will receive on starting a freeplay.
Also useful is serpent.block(table). You can use it in connection with print or messagedialog.
So e.g. game.showmessagedialog(serpent.block(game.player.character.getinventory(1).getcontents())) will show you a table of the player's inventory.

P.S. If you only changed your control.lua file there is no need to close a factorio. Starting/loading a game is enough. The updated version is used then.

Re: Modding Development Best Practices

Posted: Mon Aug 05, 2013 11:00 am
by ficolas
I just use notepad++, not an IDE, didnt even know lua had IDEs