3 Replies Latest reply on Jan 19, 2009 1:18 AM by Newsgroup_User

    Creating a list and displaying it

    Opera Rat Level 1
      I have no idea how to do this. I want to create a list if a variable is true. I have several (40) global variables, lets call them gVar1, gVar2, gVar3 the they are are either TRUE or FALSE. If they are true I want them to display each one's appropriate text say "dog", "cat", "bird" in a text field. So I would see: dog, cat, bird if they are all TRUE or cat, bird if only gVar2, and gVar3 are true.
        • 1. Re: Creating a list and displaying it
          Level 7
          Opera Rat wrote:
          > I have no idea how to do this. I want to create a list if a variable
          > is true. I have several (40) global variables, lets call them gVar1,
          > gVar2, gVar3 the they are are either TRUE or FALSE. If they are true
          > I want them to display each one's appropriate text say "dog", "cat",
          > "bird" in a text field. So I would see: dog, cat, bird if they are
          > all TRUE or cat, bird if only gVar2, and gVar3 are true.

          You could use lists instead of lots of variables.

          In a movie script:
          --------------------------------------------------
          global gDisplayOrNot, gTextToDisplay

          on prepareMovie
          gTextToDisplay=["one", "two", "three", "four"]
          gDisplayOrNot=[]
          -- initialise the flag indicating if the text should be displayed
          repeat with i=1 to count(gTextToDisplay)
          gDisplayOrNot =false
          end repeat
          end prepareMovie

          on getDisplayList
          s=""
          repeat with i=1 to count(gDisplayOrNot)
          if gDisplayOrNot
          then
          s=s & gTextToDisplay & ", "
          end if
          end repeat
          -- trim off final ", " if present
          if length(s)>0 then
          s=chars(s, 1, length(s)-2)
          end if
          return s
          end getDisplayList

          --------------------------------------------------

          Testing in the message window:

          -- Welcome to Director --
          preparemovie
          put getDisplayList()
          -- ""
          gDisplayOrNot[2]=true
          put getDisplayList()
          -- "two"
          gDisplayOrNot[4]=true
          put getDisplayList()
          -- "two, four"

          To save property lists, you can use the vList xtra or propSave xtra.

          HTH

          Andrew


          • 2. Re: Creating a list and displaying it
            Chunick Level 3
            Andrew Morton,

            remember: on the adobe site [ i ] italicizes the text... so you're code is broken.. and halfway through it's italics... so to the OP, this line:

            repeat with i=1 to count(gTextToDisplay)
            gDisplayOrNot=false

            should read like this if we switch the variable i for a k:
            repeat with k=1 to count(gTextToDisplay)
            gDisplayOrNot[k]=false
            • 3. Re: Creating a list and displaying it
              Level 7
              Chunick wrote:
              > Andrew Morton,
              >
              > remember: on the adobe site [ i ] italicizes the text...

              Yes, I'd forgotten about that. Must...resist...rant...

              Version for the web forum:
              --------------------------------------------------
              global gDisplayOrNot, gTextToDisplay

              on prepareMovie
              gTextToDisplay=["one", "two", "three", "four"]
              gDisplayOrNot=[]
              -- initialise the flag indicating if the text should be displayed
              repeat with i=1 to count(gTextToDisplay)
              gDisplayOrNot[ i ]=false
              end repeat
              end prepareMovie

              on getDisplayList
              s=""
              repeat with i=1 to count(gDisplayOrNot)
              if gDisplayOrNot[ i ] then
              s=s & gTextToDisplay[ i ] & ", "
              end if
              end repeat
              -- trim off final ", " if present
              if length(s)>0 then
              s=chars(s, 1, length(s)-2)
              end if
              return s
              end getDisplayList

              --------------------------------------------------

              Andrew