API:GetChatString

Aus WARWiki

Keine Beschreibung verfügbar.

Nutzung

API:GetChatString()


Diese Funktion übernimmt keine Argumente.


Diese Funktion gibt keine Werte zurück.


Source Code

--#         paramTable     - (table) A table containing all of the substitution parameters. This function will automatically convert numbers and strings to wstrings.
--#
--#     Returns:
--#         string         - (wstring) The text for the string table entry. Returns an empty wstring when not found.
--#
--#     Notes:
--#         This function is destructive to the paramTable input.  After GetFormatStringFromTable is called 
--#         in all of its key-value pairs, the value will now reference a widestring, and not what it formerly referenced.
--#
--#     Example:
--#     > local text = GetFormatStringFromTable( "Default", StringTables.Default.TEXT_WAR_INTRODUCTION, { GameData.Player.name, GameData.Player.career.name } )
--#
----------------------------------------------------------------------------------------------------
function GetFormatStringFromTable( tableName, id, paramTable )
    local text = L"";
    
    if( tableName == nil)
    then
        ERROR(L"Invalid parameter to GetFormatStringFromTable( tableName, id, paramTable ): tableName is nil")
    elseif( id == nil ) 
    then
        ERROR(L"Invalid parameter to GetFormatStringFromTable( tableName, id, paramTable ): id is nil")
        return text
    elseif( paramTable == nil) 
    then
        ERROR(L"Invalid parameter to GetFormatStringFromTable( tableName, id, paramTable ): paramTable is nil")
        return text
    end
      
    -- If the C-substitution is enabled, use it.
    if( GetStringFormatFromTable ~= nil ) 
    then
        -- Convert all params to wstrings   
        for index, parameter in ipairs (paramTable)
        do
            paramTable[index] = WideStringFromData (parameter)
        end
    
        text = GetStringFormatFromTable( tableName, id, paramTable ) or L""
    
    -- Else, Use the Lua subsitution
    else        
         text = GetStringFromTable(tableName, id ) or L""
             
        -- Replace each param tag with the variable
        
        for index, parameter in ipairs (paramTable)
        do
            local tag           = L"<<"..index..L">>"    
            paramTable[index]   = WideStringFromData (parameter)
            text                = wstring.gsub (text, tag, paramTable[index])
        end
    end 
    
    return text
end


Persönliche Werkzeuge
Anzeige

Sponsoren