Get ID of option in dropdown?
by Kevin Epps · in Torque Game Builder · 03/07/2007 (8:26 am) · 2 replies
How can you get the get the ID of any option added to the dropdown list?
Like if I wanted to get the id of Text that wasn't selected, how can I do that?
Like if I wanted to get the id of Text that wasn't selected, how can I do that?
About the author
#2
03/09/2007 (1:24 am)
Alternatively (although not equivalently)Quote:Or, using another class method:
GuiPopupMenuCtrl::findText( string text ) -> integer ID - Returns the position of the first entry containing the specified text.
Quote:you can simplify your function, avoiding a magic number, the use of a global variable, and a call to strcmp(), by doing something like:
GuiPopupMenuCtrl::size() -> integer size - Get the size of the menu: the number of entries in it.
function GuiPopUpMenuCtrl::getIDByText(%this, %string)
{
%size = %this.size() ;
%string = strlwr( %string ) ;
for( %count = 0; %count < %size; %count++ )
{
if ( strlwr( %this.getTextById( %count ) ) $= %string )
return
%count ;
}
return
-1 ;
}where we have added an explicit return value in the case of no hits.
Torque Owner Kevin Epps
function GuiPopUpMenuCtrl::getID(%this, %string) { for(%count = 0; %count < %highestNumberofIDs; %count++) // In my case %highestNumberofIDs = 96 { $strng = strlwr(%this.getTextById(%count)); if(strcmp($strng,%string) == 0) { return %count; break; } else { } } }