Jump to content

Chatter variation code suggestion


Recommended Posts

As @Edgeircanine428 presented here, the game doesn't handle properly when a "topic" is a table (as to introduce text variation instead of saying the same line over and over) and is accompanied by a "modifier". This change to the getmodifiedstring function in stringutil.lua could solve it:

Spoiler

local function getmodifiedstring(topic_tab, modifier)
    if type(modifier) == "table" then
        local ret = topic_tab
        for i,v in ipairs(modifier) do
            if ret == nil then
                return nil
            end
            ret = ret[v]
        end
        return ret
    else
        if modifier ~= nil and type(topic_tab[modifier]) == "table" then
            topic_tab = topic_tab[modifier]
        elseif type(topic_tab.GENERIC) == "table" then
            topic_tab = topic_tab.GENERIC
        end

        return (modifier ~= nil and topic_tab[modifier])
            or topic_tab.GENERIC
            or (#topic_tab > 0 and topic_tab[math.random(#topic_tab)] or nil)
    end
end

(Code added in bold.)

Currently this only affects mods that want to extend speech and add variation, but the base game could also benefit from this change.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...