Page 1 of 1
Setting Up a Dev Environment
Posted: Tue Mar 07, 2023 3:03 am
by xTwisteDx
Guys, I'm trying to get started working with mods for this game, however I keep running into problem, after problem, after problem trying to just setup a dev environment. I have successfully setup the following dev environments "TypeScriptToLua" using "Typed-Factorio" npm package, as well as several build scripts to successfully deploy the mod to the appropriate folder for faster iteration. I've also setup the Factorio Mod Toolkit that includes the Debug Adapter, Profiler, etc.. but that doesn't work all that well with TypeScriptToLua, and instead it's just better to build mods natively in lua. The main issue that I'm having is, what's best? Should I just embrace the suck, and develop using LUA? I don't know anything about the API, checking through documentation just shows an absolutely MASSIVE API for which to interact with, but even something as simple as trying to get a blueprint from a users "my blueprint" section seems like an absolute chore. I would like to know if there's any way to get the following information, either in LUA or TS/JS or whatever format possible.
I need Autocomplete - For my sanity.
Intellisense - I like visual studio code and I shouldn't have to guess exactly what a particular object is or does.
Debug/Breakpoints/Stepping - Again, inspecting variables on the fly would be sweet.
I've dove quite far off the deep end, and I'm really really wanting to get started on my first mod, but sheesh, this is not the easiest thing to do. Perhaps I'm too spoiled?
Re: Setting Up a Dev Environment
Posted: Thu Mar 09, 2023 11:23 pm
by Theis
I don't think it is actually possible to get "my blueprints". At least I couldn't find anything even remotely similar.
I guess you have to choose between Typescript or the mod toolkit. I would choose the latter.
Re: Setting Up a Dev Environment
Posted: Sat Mar 11, 2023 2:17 pm
by PunkSkeleton
I'm developing my 1st mod now and it's almost done so I'll try to answer some questions and give some advice. My goal is to get my mod done not setup myself for working as a mod developer. The points below are just my personal opinion.
1. For a dev environment simple text editor (like Notepad++) is sufficient. I edit the files directly in the mod folder, control script changes don't even need restart of the whole game, data and typing errors fail during game start so they're quite fast to fix.
2. Adding language conversion is just another obstacle. I don't see how could it help. Using lua to call methods on C++ objects is complicated enough. I don't like it, I'd prefer a C++ or Java API but it is how it is.
3. You should start
https://lua-api.factorio.com/latest/, there are just a few top level objects, explore from there. Google query for "Factorio lua API" unfortunately does not point at this page which made me lose some time. Also if you want to do something try to download a mod that does it and analyze the code. It helps me a lot. Especially for the things that are just weird in lua like foreach loops.
4. You can't do many things even if they seem trivial. You just need to accept this and use a workaround if possible.
5. Setting up autocomplete would probably take me longer than developing my whole mod. I just live without it.
6. The best way to debug is in my opinion using game.write_file(<your log file>, <your message>, true) but I am probably heavily biased since I do massively multi-threaded applications for a living where breakpoints are not possible.
One thing that slowed me down a lot is the fact that if you want saves (and therefore multiplayer) to work you need to note that only variables in "global" table are saved. So all global variables must be stored in that table, otherwise the game will desync.
Re: Setting Up a Dev Environment
Posted: Sat Mar 11, 2023 4:47 pm
by FuryoftheStars
I'm similar to PunkSkeleton. I just put my mods into my mod folder and use Notepad++ to edit and code them directly. I duplicate and reversion them between releases, though I probably don't even need to do that (the previous versions can all be redownloaded from your mod page).
While autocomplete and intellisense would be nice, I find trying to figure out how to set any of that up (and then I'm sure waiting for someone to update it between game releases) as not being worth the time. It's fairly easy to test and find where you've made typos and the like. The game tells you exactly what line it tripped on and why.
I've used Lua before with another, older game, and my other hobby related programming projects have been with vb.net, so the language syntax isn't an issue for me (in fact, I can understand and follow it a lot better than C/C++ or C#), but I still rely heavily on Google, the Factorio wiki (for data stage), the Factorio API (for control stage), and the modding help section of the forums. I don't think having any of the other things you're looking for would help me in that regard.
Re: Setting Up a Dev Environment
Posted: Sat Mar 11, 2023 4:58 pm
by justarandomgeek