Home Tutorials Download Forum Documentation Wiki Blog
Inherited visible state of a component

Scripting

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...

This tutorial gives you a way to know if a HUD component is visible, with taken in account the visible state of its parents.





Script

Create a function named “isComponentVisibleWithInheritance”, with a variable hComponent as parameter, which is the component you want to know the visible state.

The first step is to check if the component is not nil, in this case, you can display an error message and return false to exit the script.

Then, the idea is to check the visible state of the component, and the visible state of its parent, and the one of its parent’s parent, etc. To do that, create a loop which test the visible state of the component and then, replace the variable hComponent by its parent.

Each time, test is the component/parent is visible: if not, the base component is not visible as a component inherit of the visibility of its parents, you can return false. If it is visible, you can continue the loop until the component has no parent (when hud.getComponentContainer ( hComponent ) is nil). If the component and all of its parents where visible, the loop ends and you can return true.

The full code here:

--------------------------------------------------------------------------------
function MyAIModel.isComponentVisibleWithInheritance
( hComponent )
--------------------------------------------------------------------------------
if ( not hComponent )
then
log.error ( "Error in function 'isComponentVisibleWithInheritance', Bad argument type #0" )
return false
end
while ( hComponent )
do
if ( not hud.isComponentVisible ( hComponent ) )
then
return false
end
hComponent = hud.getComponentContainer ( hComponent )
end
return true
 
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------

Leave a Reply

Leave a Reply

You must be logged in to post a comment.