API:SetTextureImage
From RoR Wiki
UI Lua API · Interface functions
Version: WAR 1.4.8
Loads a new image file into an existing UI texture.
success = SetTextureImage(textureName, imagePath)
Arguments
- textureName
string– Name of a texture already defined by the UI, for example in a<Texture>element of a module's XML.- imagePath
string– Path of the image file, relative to the folder of the UI module that is current when the call is made.
Returns
- success
boolean–trueif the image was loaded and assigned to the texture.
Details
- The client must have a current UI module, otherwise the must be called from a UI module error is logged. The full path is built as module folder
/imagePath. - If no texture named
textureNameexists, or the image file does not exist, the matching error is logged andfalseis returned. - In the stock example the path
Textures/english/...points into theea_helpwindowmodule's own folder. - The argument check is shared with DynamicImageSetTexture: if an argument is missing or not a string, the Invalid Parameters message names that function.
- The function needs at least two arguments and only reads the last two.
Errors
These are written to the UI log; the call returns false.
Error in function call 'SetTextureImage': This function must be called from a UI moduleError in function call 'SetTextureImage': Texture %s does not existError in function call 'SetTextureImage': Image file %s does not exist
Example
Loading a localised tutorial picture and falling back to English, from ea_helpwindow/source/tutorialwindow.lua:
local function GetTextureFilePath( lang )
local langDir = InterfaceCore.CoreLanguageDirectories[ lang ]
return "Textures/"..langDir.."/"..textureFileName
end
-- First try to load the localized image
local success = SetTextureImage( "EA_Help_Tutorial_Background1", GetTextureFilePath( SystemData.Settings.Language.active ) )
if( success == false )
then
-- Otherwise fallback on the English image
SetTextureImage( "EA_Help_Tutorial_Background1", GetTextureFilePath( SystemData.Settings.Language.ENGLISH ) )
end
