SOLVED: Unable to access custom noise at runtime

Place to get help with not working mods / modding interface.
safthelamb@gmail.com
Burner Inserter
Burner Inserter
Posts: 11
Joined: Tue Aug 22, 2023 8:45 am
Contact:

SOLVED: Unable to access custom noise at runtime

Post by safthelamb@gmail.com »

Hi!

I'm having trouble accessing custom noise layers at runtime with calculate_tile_properties. I've searched around and I see that from the original post (viewtopic.php?p=438975&sid=73a3aebfb456 ... 2b#p438975), you have to add it to property_expression_names. It doesn't specify whether this is at the prototype stage or the control stage, but I've tried both to no avail:

(data)

Code: Select all

data:extend(
{
  {
    type = "noise-layer",
    name = "fertility"
  },
  {
    type = "noise-expression",
    name = "fertility",
    intended_property = "fertility",
    expression =
    {
      type = "function-application",
      function_name = "factorio-basis-noise",
      arguments =
      {
        x = noise.var("x"),
        y = noise.var("y"),
        seed0 = tne(noise.var("map_seed")),
        seed1 = tne(123),
        input_scale = tne(1/100),
        output_scale = tne(1)
      }
    }
  }
})

for _,mapgen in pairs(data.raw["map-gen-presets"]) do
  log(serpent.block(mapgen))
  for _,preset in pairs(mapgen) do
    if preset.basic_settings then
      if preset.basic_settings.property_expression_names then
        preset.basic_settings.property_expression_names["fertility"] = "fertility"
      else
        preset.basic_settings.property_expression_names = {fertility = "fertility"}
      end
    end
  end
end
(control)

Code: Select all

for _,surface in pairs(game.surfaces) do
  surface.map_gen_settings.property_expression_names["fertility"]="fertility"
end
game.print("fertility:"..serpent.block(game.players[1].surface.calculate_tile_properties({"fertility"}, {game.players[1].position})))
but the output is simply "fertility:{}". If I change this to query "temperature" instead, it works just fine!

I even tried creating a tile to generate with the noise layer so it would be "used," but no luck with that either

Code: Select all

local noise = require("noise")

local tilled_soil = util.table.deepcopy(data.raw.tile["landfill"])
tilled_soil.name = "tilled-soil"
tilled_soil.layer = 17
tilled_soil.autoplace =
{
  peaks = { noise_layer = "fertility" }
  --coverage = 0
}
data:extend({tilled_soil})
The only thing that shows I'm doing something right is that if I create a second "fertility-b" expression, then it shows up as a customizable property in the map gen settings... but again, changes nothing.

I've also tried copy pasting this code into my mod files: viewtopic.php?p=572500#p572500
But for me, the grass covers the ENTIRE area, rather than being patchy like shared in screenshots with their post.

Any ideas what I'm missing in setting up the noise layer / noise expression to be accessible at control-time?
Last edited by safthelamb@gmail.com on Wed Oct 18, 2023 10:20 pm, edited 1 time in total.
Xorimuth
Filter Inserter
Filter Inserter
Posts: 695
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Unable to access custom noise at runtime

Post by Xorimuth »

Code: Select all

 surface.map_gen_settings.property_expression_names["fertility"]="fertility"
This won’t work. You have to do this instead:

Code: Select all


local map_gen_settings = surface.map_gen_settings
map_gen_settings.property_expression_names["fertility"]="fertility"
surface.map_gen_settings = map_gen_settings
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
safthelamb@gmail.com
Burner Inserter
Burner Inserter
Posts: 11
Joined: Tue Aug 22, 2023 8:45 am
Contact:

Re: Unable to access custom noise at runtime

Post by safthelamb@gmail.com »

Hmmm, unfortunately I made that change to no avail, "temperature" still gets printed out, but "fertility" is always an empty result.

As a sanity check, I also tried disabling all other mods and left just this one, and none of them seem to be the culprit.

I've also tried not specifying an intended_property on the noise-expression, and have commented out the tile declaration to simplify things since it wasn't seeming to do anything.
safthelamb@gmail.com
Burner Inserter
Burner Inserter
Posts: 11
Joined: Tue Aug 22, 2023 8:45 am
Contact:

Re: SOLVED: Unable to access custom noise at runtime

Post by safthelamb@gmail.com »

UPDATE: I figured it out, the noise layer is not necessary for accessing this at runtime, and for some reason the noise expression cannot be named the same thing as the property being accessed.

The following works:

Code: Select all

for _,surface in pairs(game.surfaces) do
    local mgs = surface.map_gen_settings
    mgs.property_expression_names["fertility"] = "fertility-expression"
    surface.map_gen_settings = mgs
  end
  game.print("fertility:"..serpent.block(game.players[1].surface.calculate_tile_properties({"fertility"}, {game.players[1].position})))
  
Cheers!
Post Reply

Return to “Modding help”