Checking for non-existant localization

Place to get help with not working mods / modding interface.
Post Reply
FuryoftheStars
Filter Inserter
Filter Inserter
Posts: 511
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Checking for non-existant localization

Post by FuryoftheStars »

Ok, so I have an item that is procedurally generated. As such, I'm also procedurally generating the name for it.

Code: Select all

localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", {"item-name."..name}},
The problem here is that, apparently, not all the items I'm catching actually have an entry under [item-name] in the localization files and instead are using their [entity-name] entries. This results in game my item description showing the Unknown name string in these cases.

How can I check for {"item-name."..name} being non-existent and thus switch to trying {"entity-name."..name} instead?

FuryoftheStars
Filter Inserter
Filter Inserter
Posts: 511
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Checking for non-existant localization

Post by FuryoftheStars »

No one, eh? I mean, I already know neither of these work:

Code: Select all

localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", {"item-name."..name or "entity-name."..name}}
localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", {"item-name."..name} or {"entity-name."..name}}
And I'm assuming the localization doesn't even get evaluated until after the data stages. So, what can I do? Aside from manually inputting names into my own localization file, which means I need to know about them (mods).

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3512
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Checking for non-existant localization

Post by DaveMcW »

A workaround is to prefer the entity name if it exists.

Code: Select all

if item.localised_name then
  localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", localised_name}
elseif item.place_result then
  localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", {"entity-name."..item.place_result}}
else
  localised_name = {"", {"item-name.steam-loco-cartridge"}, ": ", {"item-name."..name}}
end

FuryoftheStars
Filter Inserter
Filter Inserter
Posts: 511
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Checking for non-existant localization

Post by FuryoftheStars »

Hmm, ok. I have noticed some that have item names but not entity, but those most likely don't have place results. Thanks.

Post Reply

Return to “Modding help”