Page 1 of 1

Checking if a localisation exists in data stage

Posted: Thu Jul 25, 2019 2:13 pm
by tiriscef
Hey,

I'm currently struggling with a script that is executed in the data-final-fixes stage and that should append something to the description of some items.

Code:

Code: Select all

local function append_compostable_description(item_name, humus_count)
    local prototype = data.raw.item[item_name]
    if not prototype then --item doesn't exist within the loaded mods
        return
    end

    local appendix = {"item-description.compostable", humus_count}

    if prototype.localised_description then
        prototype.localised_description = {"", prototype.localised_description, "\n", appendix}
    elseif prototype.description then
        local description = prototype.description
        prototype.description = nil
        prototype.localised_description = {"", {description}, "\n", appendix}
    else
        prototype.localised_description = appendix
    end
end
But when I'm using this script the original description of the items disappears. The script always executes the last else block.
I think this is because prototype.localized_description wasn't set in the item's declaration and the factorio engine checks if the localisation files define a description at a later stage.
So I would need to check if "item-description.<item-name>" is defined, as setting it in the declaration isn't possible because some items belong to other mods.
Is there a way to do that?

Re: Checking if a localisation exists in data stage

Posted: Fri Aug 02, 2019 2:13 pm
by eradicator
tiriscef wrote: Thu Jul 25, 2019 2:13 pm Is there a way to do that?
Short answer: No.
Long answer: Partially. If you reverse engineer the engine behavior for nil values and re-implmenent it on the lua side, you can keep the original description, but end up with "unknown key:" garbage on anything that doesn't have a description. I've made an interface request, but so far it hasn't gotten any attention (more ppl = more attention *wink*).