Splitter prototype location?

Place to get help with not working mods / modding interface.
Post Reply
Bizobinator
Fast Inserter
Fast Inserter
Posts: 193
Joined: Fri May 06, 2016 10:35 pm
Contact:

Splitter prototype location?

Post 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?

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post by ArderBlackard »

Splitter prototypes are in __base__/prototypes/entity/entities.lua. Starting at line 321 (for me) or just search for the "splitter" string.
Gib dich hin bis du Glück bist

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Splitter prototype location?

Post 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. :).

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post 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
Gib dich hin bis du Glück bist

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Splitter prototype location?

Post by DRY411S »

And there speaks an experienced modder vs a first-timer. :) *Me* starts following up the recommendation.

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post by ArderBlackard »

You must be kidding :D 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 :D 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 :oops:
Gib dich hin bis du Glück bist

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Splitter prototype location?

Post 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.

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post 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 :)
Gib dich hin bis du Glück bist

Bizobinator
Fast Inserter
Fast Inserter
Posts: 193
Joined: Fri May 06, 2016 10:35 pm
Contact:

Re: Splitter prototype location?

Post 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?

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post 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

Code: Select all

data.raw[<type>][<name>]
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.
Gib dich hin bis du Glück bist

Bizobinator
Fast Inserter
Fast Inserter
Posts: 193
Joined: Fri May 06, 2016 10:35 pm
Contact:

Re: Splitter prototype location?

Post 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? :lol:

Bizobinator
Fast Inserter
Fast Inserter
Posts: 193
Joined: Fri May 06, 2016 10:35 pm
Contact:

Re: Splitter prototype location?

Post by Bizobinator »

Actually..... a whole other question: Is this something that can even be changed in Factorio right now?

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Splitter prototype location?

Post 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?

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: Splitter prototype location?

Post 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.
Gib dich hin bis du Glück bist

Post Reply

Return to “Modding help”