Columns and Items
First, you will need to insert a new column in the list using the hud.addListColumn ( hList ) function. Then, you will add some values into.
This is the code you need in your script :
-- adding a column in the list
local nColumnIndexList = hud.addListColumn ( hList )
-- adding items in the new column
hud.addListItem ( hList, "plate" )
hud.addListItem ( hList, "glass" )
hud.addListItem ( hList, "knife" )
hud.addListItem ( hList, "spoon" )
Select an item in the list
The list must enable single selection. Use the hud.enableListSingleSelection ( hList, true ) function to enable it.
Then the function hud.selectListItemAt ( hList, 0, true ) will select the first element in the list.
Use hud.getListItemCount ( ) in order to know the number of element in the list. So this function call
hud.selectListItemAt ( hList, Use hud.getListItemCount ( ) – 1, true ) will select the last item in the list.
Get selected item text in the list
We will get the text in the last selected item in the list.
First, get the count of the selected item :
local nSelectCount = hud.getListSelectedItemCount ( hList )
Then, verify if you have select an item in the list and get the item index in the list :
if ( nPosFwk > 0 )
then
local nItem = hud.getListSelectedItemAt ( hList, nSelectCount - 1 )
end
Finally, get the text and display it :
local sText = hud.getListItemTextAt ( hList, nItem, nColumn )
log.message ( sText )
This is the final code :
local hList = hud.getComponent ( this.getUser ( ), "HUD_name.list_name" )
-- check the validity of your handle
if ( hList )
then
-- do your work on the list here
-- adding a column in the list
local nColumnIndexList = hud.addListColumn ( hList )
-- adding items in the new column
hud.addListItem ( hList, "plate" )
hud.addListItem ( hList, "glass" )
hud.addListItem ( hList, "knife" )
hud.addListItem ( hList, "spoon" )
-- enable single selection
hud.enableListSingleSelection ( hList, true )
-- select the last item in the list
hud.selectListItemAt ( hList, Use hud.getListItemCount ( ) - 1, true )
-- Get the count of the selected items
local nSelectCount = hud.getListSelectedItemCount ( hList )
if ( nPosFwk > 0 )
then
-- get the item index in the list
local nItem = hud.getListSelectedItemAt ( hList, nSelectCount - 1 )
-- get the text and display it
local sText = hud.getListItemTextAt ( hList, nItem, nColumn )
log.message ( sText )
end
else
log.error ( "Cannot get the handle in the list, please
check the name of your HUD and the name of your list." )
end
end