Prototype/NamedNoiseExpression: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Updated styling of prototype doc migration note)
(Removed old prototype docs)
Tag: Replaced
 
Line 2: Line 2:


</p><p>This wiki page is no longer updated and '''will be removed at some point in the future''', so please update your browser bookmarks or other links that sent you here. If you'd like to contribute to the new docs, you can leave your feedback [https://forums.factorio.com/viewforum.php?f=233 on the forums].</p></div>
</p><p>This wiki page is no longer updated and '''will be removed at some point in the future''', so please update your browser bookmarks or other links that sent you here. If you'd like to contribute to the new docs, you can leave your feedback [https://forums.factorio.com/viewforum.php?f=233 on the forums].</p></div>
{{Prototype parent|PrototypeBase}}
A [[Types/NoiseExpression|NoiseExpression]] together with a name.
The base game uses named noise expressions to specify functions for many map properties to be used in map generation; e.g. the "elevation" expression is used to calculate elevation for every point on a map. For a list of the built-in named noise expressions, see [[Data.raw#noise-expression]].
Named noise expressions can be used by [http://lua-api.factorio.com/latest/Concepts.html#MapGenSettings MapGenSettings] and [[Types/MapGenPreset]] to override which named expression is used to calculate a given property by having an entry in <code>property_expression_names</code> e.g. <code>elevation = "0.16-elevation"</code>.<br>
Alternate expressions can be made available in the map generator GUI by setting their <code>intended_property</code> to the name of the property they should override.<br>
Named noise expressions can also be used by [[Types/NoiseExpression#variable|noise variables]], e.g. <code>noise.var("my-named-expression")</code>.
{{Prototype TOC|noise-expression}}
== Mandatory properties ==
Inherits all properties from [[PrototypeBase]].
{{Prototype property|expression|[[Types/NoiseExpression|NoiseExpression]]}}
The noise expression itself. This is where most of the noise magic happens.
== Optional properties ==
{{Prototype property|intended_property|[[Types/string|string]]|optional=true}}
Names the property that this expression is intended to provide a value for, if any.
This will make the expression show up as an option in the map generator GUI, unless it is the only expression with that
intended property, in which case it will be hidden and selected by default.
Note that the "Map type" dropdown in the map generation GUI is actually a selector for "elevation" generators.
If generators are available for other properties, the "Map type" dropdown in the GUI will be renamed to "elevation" and shown along with selectors for the other selectable properties.
For example if a noise expression is intended to be used as an alternative temperature generator, <code>intended_property</code> should be "temperature". The base game uses the intended_properties  elevation, temperature, moisture and aux. For how the named noise expression with those intended_properties are used in the base game see the notable named noise expression list on [[Types/NoiseExpression#variable]]. Mods may add any other intended_property or modify the existing noise expressions to change/remove their intended properties. Furthermore, mods may remove the use of those named noise expressions from the map generation code or change what they affect.
=== order ===
:''See [[PrototypeBase#order]]''
Used to order alternative expressions in the map generator GUI.
For a given property (e.g. 'temperature'), the NamedNoiseExpression with that property's name as its <code>intended_property</code>
with the lowest order will be chosen as the default in the GUI.
If no order is specified, it defaults to "2000" if the property name matches the expression name
(making it the 'technical default' generator for the property if none is specified in MapGenSettings),
or "3000" otherwise.  A generator defined with an order less than "2000" but with a unique name
can thereby override the default generator used when creating a new map through the GUI without automatically overriding
the 'technical default' generator, which is probably used by existing maps.
== Examples ==
=== intended_property in the base game ===
The base game defines two named noise expressions that have the intended_property "elevation" so that are selectable via the "Map type" dropdown (which actually selects elevation generators):
<syntaxhighlight lang="lua">local noise = require("noise")
data:extend{
  {
    type = "noise-expression",
    name = "elevation",
    intended_property = "elevation",
    expression = noise.var("0_17-lakes-elevation") -- "0_17-lakes-elevation" is another named noise expression. Noise variables may reference named noise expressions.
  },
  {
    type = "noise-expression",
    name = "0_17-island",
    intended_property = "elevation",
    -- A large island surrounded by an endless ocean
    -- expression =  ...
  }
}
</syntaxhighlight>
=== Custom intended_property ===
Mods can define any intended_property with any name. This examples aims to show what this is useful for.
A [[Types/NoiseExpression#variable|noise variable]] can reference a named noise expression, so by defining the "test" named noise expression, <code>noise.var("test")</code> may be used in other [[Types/NoiseExpression|noise expressions]]. Intended_property allows to override what the variable references: With the example, if "more-test" is selected in the dropdown in the map generator GUI, its [[#expression]] (<code>noise.ridge(noise.var("y"), -10, 6</code>) will provide the value for the noise variable "test" instead.<br>
For easy demonstration, that value is assigned to the "elevation" named noise expression, so changing the "test" generator changes the <code>noise.var("test")</code> which in turn is used by the "elevation" named noise expression. The "elevation" noise variable is used by water generation, so changing the test generators is immediately visible in the map generation preview.<br>
Note that the player can select the "Island" elevation generator in the Elevation dropdown (previously named Map type), which means the 0_17-island named noise expression is selected and <code>noise.var("test")</code> isn't used anymore so changing the test generator no longer has an effect.
<syntaxhighlight lang="lua">
local noise = require("noise")
data:extend{
  {
    type = "noise-expression",
    name = "test",
    intended_property = "test",
    expression = noise.ridge(noise.var("x"), -80, 8),
  },
  {
    type = "noise-expression",
    name = "more-test",
    intended_property = "test", -- override the "test" noise variable when selected by the player
    expression = noise.ridge(noise.var("y"), -10, 6),
  }
}
data.raw["noise-expression"]["elevation"].expression = noise.var("test") -- the noise variable "test"
</syntaxhighlight>

Latest revision as of 14:32, 25 October 2024

The prototype docs have moved to a new website with an improved format. This documentation page can now be found here: https://lua-api.factorio.com/latest/prototypes/NamedNoiseExpression.html

This wiki page is no longer updated and will be removed at some point in the future, so please update your browser bookmarks or other links that sent you here. If you'd like to contribute to the new docs, you can leave your feedback on the forums.