Modding a Mod (fluidbox and recipie)

Place to get help with not working mods / modding interface.
Post Reply
Baruk
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Jun 02, 2018 9:17 am
Contact:

Modding a Mod (fluidbox and recipie)

Post by Baruk »

Hi, just started to look into things behind.

I wanted to to change a small chain in Angels Petrochem. To get sodium hydroxide you have to use the electrolyser.

I changed the recipe to get chlorine, hydrogen and sodium hydroxide solution. With FNEI and Helmod all things seems to be fine.
BUT in the recipie list of the electrolyser the water saline separation is not available, most probably because there are 3 fluid products.
So next step was to modify the electrolysers fluid box to 3 outputs (added one in the middle output side). But still no effect.
The already placed electrolysers have still 2 outputs. If I craft a new one still 2 outputs and no chance to activate the recipie.
I change he water saline separation recipie to 2 fluid output (chlorine and sodium hydroxide solution) and it worked missing the hydrogen. :-(

The continued "chain" is the crystallisation of sodium hydroxide solution to solid form. It worked so far.

My first question is: why does the electrolyser not work with 3 outputs (where do I find the working script [is there one])?
Secondly, is there a possibillity to adjust the fluid box outputs depending on the chosen recipie like assembling machines with optional fluidbox (different topic I guess, because its more on/off rather than switching in between)?
Third, is there a list to show the variables like in the assembling machine script "off_when_no_fluid_recipe = true"? I guess, its hidden in the control script section.

Hope someone can clarify some things to me.

Thanks.

Baruk

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by darkfrei »

Baruk wrote:So next step was to modify the electrolysers fluid box to 3 outputs (added one in the middle output side). But still no effect.
The already placed electrolysers have still 2 outputs. If I craft a new one still 2 outputs and no chance to activate the recipie.
I change he water saline separation recipie to 2 fluid output (chlorine and sodium hydroxide solution) and it worked missing the hydrogen. :-(
Please attach your code / your mod and we can find the error much faster.

Baruk
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Jun 02, 2018 9:17 am
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by Baruk »

This is the modified part of electrolyser.lua of angels petrochem. I just added a third output.
But the electolyser does not indicate a 3rd output (Alt-key output-triangel)
electrolyser.lua
And that is the part in recipies petrochem-chlorine.lua
I added the solution and commented out the solid-sodium-hydroxide. I changed the sequence to check whether my extra fluid works or not.
2-fluid output is working, 3 not.
recipies petrochem-chlorine.lua
That is the part in recipies petrochem-sodium.lua
The addition is the first recipie. I renames the second to solid-sodium-hydroxide-1. I don't know by now if it's neccessary.
But the good thing, it's working.
recipies petrochem-sodium.lua
Change in Items petrochem-sodium.lua to define the fluid. It's fine used as intended, but not with the recipie in mind.
Items petrochem-sodium.lua
If you need more, I don't know what to post else than the whole mod created by Angel with the tiny changes I made (for me).

If it's working in future I would try to include it into a own mod, where these parts overwriting Angels mod to let his mod untouched.

Baruk

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by darkfrei »

'angels-electrolyser' already has 4 fluid boxes:

Code: Select all

data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[1].pipe_connections[1].type = "input" 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[1].pipe_connections[1].position[1] = -2 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[1].pipe_connections[1].position[2] = -3

data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[2].pipe_connections[1].type = "input" 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[2].pipe_connections[1].position[1] = 2 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[2].pipe_connections[1].position[2] = -3 

data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[3].pipe_connections[1].position[1] = -2 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[3].pipe_connections[1].position[2] = 3 

data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[4].pipe_connections[1].position[1] = 2 
data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[4].pipe_connections[1].position[2] = 3
So, if you want to add the new input, it must be something like:

Code: Select all

if data.raw["assembling-machine"]["angels-electrolyser"] and data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes then
  local new_fluid_box = table.deepcopy(data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[1])
  new_fluid_box.pipe_connections = {type = "input", position = {0, -3}}
  table.insert (table.deepcopy(data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes, new_fluid_box)
end
With this code you don't create the same entity, but correct the old one if it exists.

Output is the same, but here must be copied third fluid box:

Code: Select all

if data.raw["assembling-machine"]["angels-electrolyser"] and data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes then
  local new_fluid_box = table.deepcopy(data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes[3])
  new_fluid_box.pipe_connections = {position = {0, 3}}
  table.insert (table.deepcopy(data.raw["assembling-machine"]["angels-electrolyser"].fluid_boxes, new_fluid_box)
end

Baruk
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Jun 02, 2018 9:17 am
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by Baruk »

Thanks for the reply. It makes fully sense. The only thing I wonder is; where did you find this code parts?

I searched them, thinking something has to exist, but was not lucky to find it.

I am at the stage to modify the original code writen by Angel by implementing already the 3rd output in the buildings definition part, or miss I something?

Baruk

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by darkfrei »

Baruk wrote:Thanks for the reply. It makes fully sense. The only thing I wonder is; where did you find this code parts?
My mod info-mod: viewtopic.php?f=135&t=45107
You can find whole data.raw into .log file. You are also need something like Notepad++ for 10-100 MB files opening.

Baruk
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Jun 02, 2018 9:17 am
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by Baruk »

Again many thanks.

Just to prove my understanding.

The building prototypes are only read at first use or even the beginning of the game/ adding the mod. Thereafter it is stored in the game database and will be used regardless of changes in the prototype. Because entities already created, either placed or in inventory, changes are only possible by manipulating the tables.

So my further goal to write an own mod is by nature the only practicle way to introduce such things in running games.

I started a new game and there it works as intended by shortcutting in creative.

Baruk

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Modding a Mod (fluidbox and recipie)

Post by eradicator »

Baruk wrote:The building prototypes are only read at first use or even the beginning of the game/ adding the mod. Thereafter it is stored in the game database and will be used regardless of changes in the prototype. Because entities already created, either placed or in inventory, changes are only possible by manipulating the tables.
No. Just no. There's no "database" that stores how stuff looked when it was "built". Before the game starts (i.e. before you get to the main menu) all data/-updates/-final-fixes are evaluated to build the prototypes. This is done every time the game starts, there is no cache. A savegame only stores the name of a building. So if you build a "my-building-1", save the game, quit, change the definition of "my-building-1" then the thing in your savegame will be whatever the new definition says it is. If you're experiencing any sort of behavior that looks like "this change only works on newly built buildings" then you're doing something wrong. In your example probably something involving names. Maybe you're defining the same prototype twice and thus the first one is overwritten by the second one? Hard to tell via the code snippets. Making a new mod that modifies another mod is much cleaner and easier to debug than editing someone elses huge mod that you know almost nothing about ;).

Post Reply

Return to “Modding help”