Michael,
As you said, you really don't want to use an array structure to
represent your data since you do not have the same number of
subchapters, subsubChapters, etc. in all chapters.
First thing to do is to seperate out (in your mind), the underlying
data structure - and the code used to display your structure on the
screen. These are two completely different things.
What you really want to use to represent your data is nested lists.
The implementation of your data structure will be very dependant with
the functionality you want to provide. But the basic concept is to
have a nested property list where each name is the name of the movie,
and the value a list of all sub things to that movie. Using your
example, you could create a nested list like this (just going down
three levels for clarity) (completely untested, don't even know if
it would compile):
MyGlobalBigNestedList =\
["MovieFor1": \
["MovieFor11":
["MovieFor111":[], "MovieFor112":[]", "MovieFor113":[]],\
["MovieFor12":
["MovieFor121":[], "MovieFor122":[]", "MovieFor123":[]],\
["MovieFor13":
["MovieFor131":[], "MovieFor132":[]", "MovieFor133":[]],\
],\
["MovieFor2": \
["MovieFor21":
["MovieFor211":[], "MovieFor212":[]", "MovieFor213":[],
"MovieFor214":[]],\
["MovieFor22":
["MovieFor221":[], "MovieFor222":[]", "MovieFor223":[]],\
["MovieFor23":
["MovieFor231":[], "MovieFor232":[]", "MovieFor233":[],
"MovieFor234":[], "MovieFor235":[]],\
],\
etc.
Then you can write either a recursive routine or a routine with a
repeat loop to get at any item at any level. For example (again
untested):
on GetMovieName stringToGetThere -- for example "162"
nChars = the number of chars in stringToGetThere
lData = duplicate(MyGlobalBigNestedList)
-- Use this repeat loop to go down one level of the hierarchy
-- each time through
repeat with index = 1 to nChars
thisChar = char index of stringToGetThere
indexIntoThisPropList = value(thisChar)
thisMovieName = getPropAt(lData, indexIntoThisPropList)
lData = getAProp(lData, thisMovieName)
end repeat
return thisMovieName
end
You can write a very similar routine as the above to add to the hierarchy:
on AddMovieName stringToGetThere, newName
-- very similar to the above,
-- but if you get to a level that does not yet exist, you need to add
-- a new level
-- and when you get down to the bottom, you add "newName" to the list.
end
Hope this gives you a starting point.
Irv
At 1:23 AM +0200 5/20/01, Michael von Aichberger wrote:
>Hi everybody and good evening to all of you who work on weekends!
>
>I have a problem that is too difficult for me alone to solve:
>
>I want to generate a sitemap dynamically. As chapters are added they should
>be displayed in a tree-like hierarchical menu and be accessible by that
>menu. Let's say I have a main menu, I name it "1" From there I can choose
>out of three chapters, I name them "11", "12" and "13". Each of the chapters
>has an unpredictable number of subchapters. I think you get the idea.
>
>If it weren't the tree structure but something linear, it would be simple to
>put all chapters in a linear list. Now I probably have to build a
>multidimensional array, the branches of which have an unregular number of
>sub-branches and so forth.
>
>The multidimensional array will contain links to the respective movies that
>can be run by choosing them in the sitemap.
>
>How can this be done in an elegant manner? I have tried it for hours now,
>but my main problem is: If my item is in the fourth hierarchy (for instance
>"1615") then I would have to retrieve my value with a something like: value
>= array[1][6][1][5]. This only works if in the first hierarchy there are at
>least 1, in the second 6 in the third 1 and in the fourth 5 elements . As I
>said, I want to create that tree dynamically, so it is possible that I might
>have to create an element for which there are no branches yet that lead to
>that element. I have to create them, before I place my value in the new
>place. If I don't, naturally, I get an index out of range error. But how do
>I check if in my array there are the branches that are needed and how do I
>create them with a minimal effort?
>
>Thank you very much for your suggestions!
>
>Michael von Aichberger
>
>
>[To remove yourself from this list, or to change to digest mode, go to
>http://www.penworks.com/LUJ/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!]
--
Lingo / Director / Shockwave development for all occasions.
(Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/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!]