Weird code in Electric Mining Drill?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
Xerus
Burner Inserter
Burner Inserter
Posts: 19
Joined: Wed Jul 19, 2017 8:44 am
Contact:

Weird code in Electric Mining Drill?

Post by Xerus »

When I wanted to make my own drill, i looked at the prototype for the electric mining drill and found this:

Code: Select all

    energy_source =
    {
      type = "electric",
      -- will produce this much * energy pollution units per tick
      emissions = 0.15 / 1.5,
      usage_priority = "secondary-input"
    }
why write 0.15/1.5 and not simply 0.1? Is there any reason?

Patashu
Fast Inserter
Fast Inserter
Posts: 130
Joined: Mon May 08, 2017 11:57 pm
Contact:

Re: Weird code in Electric Mining Drill?

Post by Patashu »

Sometimes it's more useful to show how a number was arrived at than to just write the number. For example, if you had a 1024x768 game and wanted the constant '30 less than 1024', your intent is clearer if you write 1024-30 than if you write 994.

Why it's 0.15 / 1.5 specifically I don't know - maybe all emission values were divided by 1.5 at one point, and it's just been left like that since?

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

Re: Weird code in Electric Mining Drill?

Post by darkfrei »

It can be just dividing or two parameters like by resistance
https://wiki.factorio.com/Damage

User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 213
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

Re: Weird code in Electric Mining Drill?

Post by QGamer »

So...I've been doing some modding of my own, and I noticed a few things:

1) Tons of entities have code like that. It's not limited to mining drills.

Code: Select all

emissions = some # / some other #
2) The pollution an entity emits is energy_source.emissions times the energy consumption in kW.

3) This format is useful for getting exact numbers of pollution. In a mod I'm making, I wanted an entity to output 15 pollution and consume 325 kW.

This:

Code: Select all

emissions = 3 / 65
...is in my opinion better than this:

Code: Select all

emissions = 0.04615384615
"Adam fell that men might be; and men are, that they might have joy."

Post Reply

Return to “Modding discussion”