how to print to console when you reach the limit of LocalisedString

Place to get help with not working mods / modding interface.
User avatar
Stargateur
Filter Inserter
Filter Inserter
Posts: 352
Joined: Sat Oct 05, 2019 6:17 am
Contact:

how to print to console when you reach the limit of LocalisedString

Post by Stargateur »

So, I want to print a list of entities on the console, that works well but we can't scroll the console output so I decided to instead of doing one entity per line I concat all into one line. And then... I discover I can't concat more than 20 (well actually 19 cause the first "" count...) with LocalisedString array. I end up solving the problem using deeper level... I really don't get why there is a limit of 20 for the array, for the recursion okay why not but for the array ??? Anyway here some snipped if you know better please advice

Code: Select all

  local i = 1
  local line = {""}
  for type, qualities in pairs(entities_count) do
    if i > 20 then
      print(line)
      i = 1
      line = {""}
    end
    local tmp = {"", " ⚙ ", prototypes.entity[type].localised_name}
    for quality_name, count in pairs(qualities) do
      local quality = prototypes.quality[quality_name]
      local c = quality.color
      local color = string.format("#%.2x%.2x%.2x%.2x", c.a * 255, c.r * 255, c.g * 255, c.b * 255)
      table.insert(tmp, {"", string.format(": [color=%s]", color), quality.localised_name, string.format("[/color]: %d", count)})
    end
    table.insert(line, tmp)
    i = i + 1
  end
  print(line)
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4345
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: how to print to console when you reach the limit of LocalisedString

Post by boskid »

LocalisedString's recursion limit being 20 levels is documented since 1.1.22. Please consider not splicing localised strings and instead using log() for whatever debugging purpose you need it.
User avatar
Stargateur
Filter Inserter
Filter Inserter
Posts: 352
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: how to print to console when you reach the limit of LocalisedString

Post by Stargateur »

boskid wrote: Wed Dec 17, 2025 7:49 pm LocalisedString's recursion limit being 20 levels is documented since 1.1.22.
I talk more about parameter limit than recursion limit and I never imply it was new
boskid wrote: Wed Dec 17, 2025 7:49 pm Please consider not splicing localised strings
What ? my very problem is I'm forced to do this - - I wish I could just do "utils.get_translation(localisation_string)"
boskid wrote: Wed Dec 17, 2025 7:49 pm instead using log() for whatever debugging purpose you need it.
That not debugging and that irrelevant, debugging or not the problem is here. And honestly I wouldn't use localization for debug output

---

Well I end up with this:

Code: Select all

  line = ""
  for type, qualities in pairs(entities_count) do
    for quality_name, count in pairs(qualities) do
      local quality = prototypes.quality[quality_name]
      line = string.format("%s[entity=%s,quality=%s] %d ", line, prototypes.entity[type].name,  quality.name, count)
    end
  end
  print(line)
Not what I wanted but work
Last edited by Stargateur on Wed Dec 17, 2025 8:05 pm, edited 1 time in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16392
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: how to print to console when you reach the limit of LocalisedString

Post by Rseding91 »

If you have so much data to show that you can't fit it all on-screen consider making a custom GUI to show it runtime. The chat window is and was never meant as a place to output that much information. It was meant for short one-off bits of information (hence why it fades out, and has a limited amount of space shown on screen).
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”