Index from structure search

pho's picture

Hi,

I have the following structure: 0: (0) Author 1: (1) Editor 2: (2) Publisher 3: (3) etc.

How can I get the Index of an item by searching for a keyword?

For instance, if I searched for Editor I would get 1 as a result.

regards

Achim Breidenbach's picture
Re: Index from structure search

I think this is only possible if you use some kind of scripting language. Even I don't recommend to use JavaScript for some reasons here is an example:

function (__number outIndex) main (__structure inStructure, __string inKey)
{
   outIndex = -1;
 
   if(inStructure != null)
   {
      for (var i = 0; i < inStructure.length; i++)
      {
           if(inStructure[i] == inKey)
           {
              outIndex = i
           }
      }
   }
 
   var result = new Object();
   result.outIndex = outIndex;
   return result;
}

Thats how the function would look like in LUA (read more about the LUA plugin here: http://docs.boinxtv.com/lua_patch )

inStructure = QC_STRUCT
inKey = QC_STRING
 
outIndex = QC_NUMBER
 
main = function()
 
   outIndex = -1
 
   if inStructure ~= nil then
      for key,value in pairs(inStructure) do
         if value == inKey then
            outIndex = key - 1
         end
      end
   end
 
end

pho's picture
Re: Index from structure search

Thank you! It works perfectly.