ITexture.IsError

From GMod Wiki

Jump to: navigation, search
Function
Syntax ITexture:IsError( )
Description:
Returns false if the specified texture initialized properly, and true if it didn't.
Returns: Boolean
In Object: ITexture
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=ITexture.IsError]ITexture.IsError [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionCreates a method that checks if a texture is valid
Used onClient
Code
function IsValidMaterial( strName )
	local mat, basetex
 
	mat = Material( strName )
	basetex = mat:GetMaterialTexture( "$basetexture" )
 
	return not basetex:IsError( )
end
 
function SafeSetMaterial( strName )
	if not IsValidMaterial( strName ) then
		LocalPlayer( ):SetMaterial( "" )
	else
		LocalPlayer( ):SetMaterial( strName )
	end
end
 
SafeSetMaterial( "models/purple" )
OutputIf the texture "models/purple" is valid, the local player has their material set to that, else their material is cleared


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox