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.


Repairable objects' inspect string can cause crashes

Recommended Posts

squeek    236

From the The Big List Of Mod-Related Code Suggestions

Fix repairable item describe strings (multiple bugs exist; one can cause crashes)

Detailed here. Example fix here (the function is in stringutil.lua)

The GetDescription function of stringutil.lua will crash if STRINGS.CHARACTERS[charactername] exists but STRINGS.CHARACTERS[charactername].DESCRIBE[prefabname] doesn't (almost a certainty for custom characters and/or custom repairable items). It also incorrectly handles generic/character-specific strings (if a character-specific prefab describe string exists, but a character-specific repairable string doesn't, then it won't append any repair string and vice versa; if no prefab-specific string exists at all, it will never append the repair string)

A completely fixed GetDescription function:


function GetDescription(character, item, modifier)    character = character and string.upper(character)    local itemname = item.components.inspectable.nameoverride or item.prefab    itemname = itemname and string.upper(itemname)    modifier = modifier and string.upper(modifier)     local ret = GetSpecialCharacterString(character)     if not ret then        if STRINGS.CHARACTERS[character] then            ret = getcharacterstring(STRINGS.CHARACTERS[character].DESCRIBE, itemname, modifier)        end                 if not ret and STRINGS.CHARACTERS.GENERIC then            ret = getcharacterstring(STRINGS.CHARACTERS.GENERIC.DESCRIBE, itemname, modifier)        end             if not ret and STRINGS.CHARACTERS.GENERIC then            ret = STRINGS.CHARACTERS.GENERIC.DESCRIBE_GENERIC        end             if ret and item and item.components.repairable and item.components.repairable:NeedsRepairs() and item.components.repairable.announcecanfix then            local repairstring = nil                 if STRINGS.CHARACTERS[character] and STRINGS.CHARACTERS[character].DESCRIBE then                repairstring = getcharacterstring(STRINGS.CHARACTERS[character], "ANNOUNCE_CANFIX", modifier)            end                 if not repairstring and STRINGS.CHARACTERS.GENERIC then                repairstring = getcharacterstring(STRINGS.CHARACTERS.GENERIC, "ANNOUNCE_CANFIX", modifier)            end                         if repairstring then                ret = ret..repairstring            end        end    end     return retend

Share this post

Link to post
Share on other sites