Hi Tim,

Recursion is the answer to this. Here is a sample of how this works.

--movie handler
on nestedListRetrieval aList, aPath
  c = aList.count
  if aPath[1] > c then return void
  tValue = aList[aPath[1]]
  if aPath.count > 1 then
    aPath.deleteAt(1)
    tResult = nestedListRetrieval(tValue, aPath)
    return tResult
  else
    return tValue
  end if
end

--in the message window

tList = [[[1,2],[3,4],[5,6]],[[7,8],[9,0]]]
put tList[1][3][2]
--6
put nestedListRetrieval(tList, [1,3,2])
--6

tList = [[[1,2],[3,4],[5,6]],[[7,8],[9,0]]]
put tList[1][4][2]
--index out of range

put nestedListRetrieval(tList, [1,4,2])
--<void>

You can modify this and make it more sophisticated, like returning extactly where in the path it chocked, but at the very least you should add some error checking before you drill down at level to make sure you are indeed passing a list.

hth,

Rob


On Wed, 18 Aug 2004 10:36:58 +0100, Tim Welford <[EMAIL PROTECTED]> wrote:

Hi,

I am using the XMLParser Xtra within a director 8.5 movie, and I'm
outputting the parsed XML to a lingo list with the makeList command.

This produces large multi dimensional lists that I have to work with,
it's a pain to bug fix, but that's not the current issue.

Although I will always be 99.9% sure that the xml layout will always be
the same, I would like to check that a specific list element exists
before trying to access it and protect myself against any "index out of
range errors".

The list element I am accessing (for example) may look like this:
theList[1][2][4][2][1][1]

Is there any way I can check that this list element exists, apart from
doing a huge nested if / loop to check the count of each dimension
before moving onto the next dimension if the count is >= the element I
want?  Something like "if varExists(theList[1][2][4][2][1][1]) then".

A nested if would be fine for 1 or 2 accesses, but I need to access
potentially hundreds of elements.





[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to