Page 1 of 1
Splitter prototype location?
Posted: Wed Jun 01, 2016 3:53 pm
by Bizobinator
Hey all, first time modder here, dipping my toes in the water.
I'm trying to make a mod that allows the player to select the vanilla (& Bob's mods) splitters and control the split ratio. However, I cannot seem to find the splitter prototype? I'm probably sure it will be something super simple/that I overlooked. Or, is it one of those things that is hard-coded?
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 4:12 pm
by ArderBlackard
Splitter prototypes are in __base__/prototypes/entity/entities.lua. Starting at line 321 (for me) or just search for the "splitter" string.
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 6:53 pm
by DRY411S
As a first time modder myself, I wish you luck. The people here are very helpful, and I've had replies to my questions from some of the modfathers of factorio. It's great to see that they are willing to support humble beginners.
If you are not doing so already, I'd really recommend using Notepad++. It's LUA context sensitive as you're building mods, and due to way that the prototypes are scattered amongst the base file,s has a great 'Find In Files' feature that will (once you have configured it) be something that you wonder how you never managed without.
.
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 7:20 pm
by ArderBlackard
I'd highly recommend the JetBrains IntelliJ IDEA with Lua plugin (the Community Edition is completely free and opensource). It provides not only a project management, quick search, but also advanced code-highlighting (like separate styles for global/local variables/fields/closures etc.), a number of (quite simple but anyway) refactorings like variables renaming; code analysis (unused variables, assignments), integration with version control systems (e.g. GitHub) and many other functions.
I've tried many editors/IDEs so far (Notepad++, VSCode, Sublime, ZeroBrane) - IDEA seems the best for me.
EDIT: It's also crossplatform. Win/Linux/OS X
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 7:30 pm
by DRY411S
And there speaks an experienced modder vs a first-timer.
*Me* starts following up the recommendation.
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 7:42 pm
by ArderBlackard
You must be kidding
I'm quite a newbie to Factorio (discovered it only since Steam release unfortunately). But you might know how it happens: you start trying to play on Friday evening and then suddenly it's Monday morning
The thing that helps me a bit is that I'm a programmer IRL so it was not so unusual to get aquainted with Lua scripting
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 8:38 pm
by DRY411S
And IRL I was a programmer between 1979 and 1981 before entering the IT management rat race, and am always many years behind the curve on the part of IT that I wish I'd never left behind.
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 8:52 pm
by ArderBlackard
For those once involved it's never too late, I believe. It's just a matter of having an interesting project to work at
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 8:54 pm
by Bizobinator
ArderBlackard wrote:Splitter prototypes are in __base__/prototypes/entity/entities.lua. Starting at line 321 (for me) or just search for the "splitter" string.
Excellent. Thanks!
ArderBlackard wrote:I'd highly recommend the JetBrains IntelliJ IDEA with Lua plugin (the Community Edition is completely free and opensource). It provides not only a project management, quick search, but also advanced code-highlighting (like separate styles for global/local variables/fields/closures etc.), a number of (quite simple but anyway) refactorings like variables renaming; code analysis (unused variables, assignments), integration with version control systems (e.g. GitHub) and many other functions.
I've tried many editors/IDEs so far (Notepad++, VSCode, Sublime, ZeroBrane) - IDEA seems the best for me.
EDIT: It's also crossplatform. Win/Linux/OS X
I'll have to give that a try. It sounds interesting....
Oh, also, how do I make a mod that just modifies something in vanilla? Do I have to go through creating a whole new object? Is there a tutorial for this sort of thing that you all would recommend?
Re: Splitter prototype location?
Posted: Wed Jun 01, 2016 9:48 pm
by ArderBlackard
Something of what I'm going to write you may already know
The idea is to get the filled
data.raw table containing all the prototypes to be used in the game after all prototypes definition stages.
After the prototype is defined it is assumed to be stored under
where <type> is the prototype type and <name> is it's name (should be unique among the same type prototypes AFAIK). There is a convenient function
data:extend which adds passed in prototypes to
data.raw table based on their types/names.
So you may either replace the existing prototypes with your own or just change some values in those already defined.
Lets consider as an example a vanilla solar panel definition (it's relatively short, but still I've omitted some fields):
Code: Select all
data:extend {
...
{
type = "solar-panel",
name = "solar-panel",
...
max_health = 100,
corpse = "big-remnants",
...
production = "60kW"
},
...
}
After this call the solar panel prototype can be found at
Code: Select all
data.raw["solar-panel"]["solar-panel"]
Here the type and the name are the same ("solar-panel") but the type comes first.
And you may replace it with the full definition like
Code: Select all
data.raw["solar-panel"]["solar-panel"] =
{
type = "solar-panel",
name = "solar-panel",
...
max_health = 1000,
corpse = "small-remnants",
...
production = "6000kW"
}
or just tune some of it's properties:
Code: Select all
data.raw["solar-panel"]["solar-panel"].max_health = 1000
data.raw["solar-panel"]["solar-panel"].corpse = "small-remnants"
data.raw["solar-panel"]["solar-panel"].production = "6000kW"
To make sure you are modifying the existing prototypes you need to know that you are doing it
after they have been defined. Unfortunately I can't state I'm fully aware of all the mods loading precedence rules (at least it seems to be defined by mods dependencies and ordering by mod names), but there are some guaranteed approaches: there are three iterations of running prototypes definition scripts (if present): running 'data.lua' for all the mods, then 'data-updates.lua' for all mods, than 'data-final-fixes.lua' (more details at
https://wiki.factorio.com/index.php?tit ... _Lifecycle). As vanilla game defines all prototypes in 'data.lua', you may safely use 'data-updates.lua' to redefine or change the base prototypes.
Re: Splitter prototype location?
Posted: Thu Jun 02, 2016 8:25 pm
by Bizobinator
Thanks Arder! That should help a bunch.
I'm hoping to make it something that's changeable in-game; you'd click on the spliter, and then you could adjust the split ratios with up & down arrows. What sort of special coding will I need to set that up?
Is this a bit too advanced for a 1st-time mod?
Re: Splitter prototype location?
Posted: Thu Jun 02, 2016 8:38 pm
by Bizobinator
Actually..... a whole other question: Is this something that can even be changed in Factorio right now?
Re: Splitter prototype location?
Posted: Thu Jun 02, 2016 9:09 pm
by golfmiketango
ArderBlackard wrote:I'd highly recommend the JetBrains IntelliJ IDEA with Lua plugin (the Community Edition is completely free and opensource). It provides not only a project management, quick search, but also advanced code-highlighting (like separate styles for global/local variables/fields/closures etc.), a number of (quite simple but anyway) refactorings like variables renaming; code analysis (unused variables, assignments), integration with version control systems (e.g. GitHub) and many other functions.
I've tried many editors/IDEs so far (Notepad++, VSCode, Sublime, ZeroBrane) - IDEA seems the best for me.
EDIT: It's also crossplatform. Win/Linux/OS X
Question, does that somehow support out-of-process debugging of scripts running in factorio? Or is it effectively just a very fancy text editor when used for mod development?
Re: Splitter prototype location?
Posted: Thu Jun 02, 2016 9:20 pm
by ArderBlackard
Bizobinator wrote:
I'm hoping to make it something that's changeable in-game; you'd click on the spliter, and then you could adjust the split ratios with up & down arrows. What sort of special coding will I need to set that up?
Well... I'm not 100% sure that it is possible. Still you may give it a try, but it will definitely require some additional coding.
If it can be done somehow for now, then you will likely need to use the
LuaEntity.get_transport_line() function to get the input/output lines of a splitter and manage their content using
LuaTransportLine functions.
It's only a hypothesis though.
golfmiketango wrote:Question, does that somehow support out-of-process debugging of scripts running in factorio? Or is it effectively just a very fancy text editor when used for mod development?
Nope, in regard to Factorio modding it does not provide a run-time debugger. But I'm also not aware of any other way to attach a Lua-debugger to Factorio.