32 Replies Latest reply on Mar 4, 2008 4:12 PM by ytlevine

    Couple of Scripting questions

    ytlevine Level 1
      I have a few scripting questions that I need help with. I am using Lingo.
      First question:
      I am using the BuddyAPI getfilename function to open an "open" dialog. When a file is selected, it returns the full path of the file, e.g. C:\MyFolder\mydoc.txt. Is there any way to get a variable from this with either just "mydoc"(in the example) or "mydoc.txt"?
      #2: If I change the association of a video member, is there a way to have it 1)detect the size 2) resize the sprite 3)resize the projector window if neccesary? (I can probably just make the projector window big enough so there is no need to set the size)?
      3: If I want to load a few files, and want them to be separate variables, e.g. file1, file2, etc., is there a way to use the variables with the same name, and have it go to the first available one - if file(#) > "" then use variable file(# + 1)?
      4: Is there a way to load multiple video files to play in a row, and give the option to add a file to the existing list?

      I really appreciate all help!
      Thanks!
        • 1. Re: Couple of Scripting questions
          Level 7
          You can set the itemDelimiter and grab the last item:
          tFilename = baGetFilename(...)
          tDelim = the itemDelimiter
          the itemDelimiter = the last char of the moviePath
          tFile = the last item of tFilename
          the itemDelimiter = "."
          tName = tFile & ""
          delete the last item of tName
          the itemDelimiter = tDelim
          -- tName = "myDoc"; tFile = "myDoc.txt"

          > #2: If I change the association of a video member, is there a way to have it
          > 1)detect the size 2) resize the sprite 3)resize the projector window if
          > neccesary? (I can probably just make the projector window big enough so there
          > is no need to set the size)?

          What do you mean by "change the association of a video member"? I'm
          guessing you mean change its filename. If so, you can query member.width
          and member.height after setting member.filename and use this to set
          sprite.width and sprite.height and adjust your projector window size if
          required.

          > 3: If I want to load a few files, and want them to be separate variables, e.g.
          > file1, file2, etc., is there a way to use the variables with the same name, and
          > have it go to the first available one - if file(#) > "" then use variable
          > file(# + 1)?

          I'm not understanding your question, but it looks/sounds like a list
          might apply for the job.

          > 4: Is there a way to load multiple video files to play in a row, and give the
          > option to add a file to the existing list?

          You can "load" multiple files to play in a row by monitoring the sprite
          playing the current video for completion then swap the member.filename
          and so forth until done.
          As far as adding to an existing list, it can be done but details depend
          on your implementation. That is, you need to provide more detail.
          • 2. Couple of Scripting questions
            ytlevine Level 1
            Thanks for the reply.
            This delimiter is a Director function, or a BuddyAPI function? And I type it the way you did, or you are giving me the general idea? Can I find more info about these functions in the help files? And which of these are variables?
            Also, I did mean change the filename - that should work. And once I change the filename, the member should "know" the width and height? Andhow would I resize the projector window?
            quote:

            but it looks/sounds like a list might apply for the job.

            I thought of a list, but I want a way to display a sort of "playlist" and have it highlight which item is playing, and be able to clck on separate items, so I figured I had to use variable instead. Will I be able to use a list for that? And if so, where would I get more info about lists?
            Thanks!!
            • 3. Re: Couple of Scripting questions
              Level 7
              > This delimiter is a Director function, or a BuddyAPI function? and I type it
              > the way you did, or you are giving me the general idea?

              You can copy and paste exactly what I wrote - I tested it in my message
              window.

              > Also, I did mean change the filename - that should work. And once I change the
              > filename, the member should "know" the width and height?

              Yes.

              > Andhow would I resize
              > the projector window?

              You'd set the rect of the window.

              >
              quote:

              but it looks/sounds like a list might apply for the job.

              > I thought of a list, but I want a way to display a sort of "playlist" and have
              > it highlight which item is playing, and be able to clck on separate items, so I
              > figured I had to use variable instead. Will I be able to use a list for that?
              > And if so, where would I get more info about lists?

              I'm not going to write your application for you, but in general terms
              you could stash your filenames in a list, present this list in a #text
              member/sprite, and highlight individual lines based on which file is
              playing at the same time as you swap one file for another.
              • 4. Re: Couple of Scripting questions
                ytlevine Level 1
                Sean, thanks for all your help. One last thing:
                >I'm not going to write your application for you, but in general terms
                >you could stash your filenames in a list, present this list in a #text
                >member/sprite, and highlight individual lines based on which file is
                >playing at the same time as you swap one file for another.
                And in order to swap files, I can use the info in a list and tell it to use the next line after the current file is done?
                • 5. Re: Couple of Scripting questions
                  Level 7
                  > And in order to swap files, I can use the info in a list and tell it to use
                  > the next line after the current file is done?

                  Yes. Imagine you have a list of filenames of videos. When you start them
                  playing you "remember" (property variable) that the file you're playing
                  is at index position 1 in the list (implying that you "hilite" line 1 in
                  your text member). When video[1] is finished you increment your index
                  counter (property), check to see whether it's a valid index (if newIndex
                  <= count(list)) then swap the member.filename for this next position in
                  the list and hilite the appropriate line in the text member.
                  • 6. Re: Couple of Scripting questions
                    ytlevine Level 1
                    Thanks, Sean, for all your help.
                    I haven't used lists too much, but I will read up on it and try your suggestions.
                    Keep up the good work!!
                    • 7. Re: Couple of Scripting questions
                      Level 7
                      Believe me, once you start working with lists (both linear lists and
                      property lists) you will wonder how you ever did anything without them.
                      • 8. Couple of Scripting questions
                        ytlevine Level 1
                        I read up on lists a bit, and I see the usefullness - will make my work a lot easier now.
                        Two more questions - what type of list should I use for this - a linear list, or a property list?
                        And, assuming I understand how to do this, can I use a variable to remember the position in the list - like:
                        "getAt(mylist, n)"
                        and then go to the next one, like:
                        "n = n+1"?
                        Also, is there any way to set up a way to drag and drop a file to a window, and it will get the pathname?
                        Thanks!
                        • 9. Re: Couple of Scripting questions
                          Level 7
                          what type of list should I use for this - a linear list,
                          > or a property list?

                          Probably a linear list would be fine for your purpose. Just list of
                          filenames like

                          listOFilenames=["c:\path\to\file1","c:\path\to\file2"]

                          > And, assuming I understand how to do this, can I use a variable to remember
                          > the position in the list - like:
                          > getAt(mylist, n), and then go to the next one, like n = n+1?
                          yes.

                          put listOFileNames[1]
                          -- "c:\path\to\file1"

                          repeat with i=1 to listOFileNames.count
                          put listOFileNames
                          end repeat

                          -- "c:\path\to\file1"
                          -- "c:\path\to\file2"

                          > Also, is there any way to set up a way to drag and drop a file to a window,
                          > and it will get the pathname?

                          There is a (windows only) xtra called dropFile which can do that:

                          http://www.mediamacros.com/item/item-930154949/
                          • 10. Re: Couple of Scripting questions
                            Level 7
                            "what type of list should I use for this - a linear list, or a property
                            list?"

                            As Sean suggested, a simple linear list is all you would need for this.
                            I didn't mean to confuse you by mentioning property list, just wanted
                            you to know that once you learn linear list, don't stop there!

                            "can I use a variable to remember the position in the list - like:
                            getAt(mylist, n), and then go to the next one, like n = n+1?"

                            I assume you intend n to be a global variable. Yes this will work, but
                            an even better way is for both the list and the counter to be custom
                            sprite properties that you define. This is another "intermediate" level
                            programming technique (object oriented programming) that you will want
                            to master at some point.

                            "is there any way to set up a way to drag and drop a file to a window,
                            and it will get the pathname?"

                            I'm not sure about that one, but you can easily use something like
                            FileXtra4 or FileIO to display the standard "Open file" browser dialog
                            box, which allows users to browse for files and returns the full path to
                            the file they selected.

                            I sincerely hope this isn't discouraging you. It sounds like you are
                            getting close and I am sure you can get it all working. Keep coming back
                            with more questions. Usually, the more specific the question, the more
                            specific the answers will be.




                            • 11. Couple of Scripting questions
                              ytlevine Level 1
                              >yes.
                              >
                              >put listOFileNames[1]
                              >-- "c:\path\to\file1"
                              >
                              >repeat with i=1 to listOFileNames.count
                              >put listOFileNames
                              >end repeat

                              Sorry - I am not familiar with the function.
                              What will the above do?

                              Also,
                              >There is a (windows only) xtra called dropFile which can do that:

                              > http://www.mediamacros.com/item/item-930154949/
                              I checked the website out, and downloaded the file.
                              Only question - it seems old, and there is no working link yo the original website.
                              Should it still work, and do you know of a newer version?
                              Unless this was included in BuddyAPI?
                              Thanks!
                              • 12. Re: Couple of Scripting questions
                                Level 7
                                My sample was just a repeat loop showing you how you can use a variable
                                to find the items in the list.

                                The dropfile xtra is quite old, but I have used it successfully. It is
                                windows only, though, so don't use it if you plan on publishing for Mac.
                                • 13. Re: Couple of Scripting questions
                                  Level 7
                                  > There is a (windows only) xtra called dropFile which can do that:
                                  >
                                  > http://www.mediamacros.com/item/item-930154949/

                                  Now that is cool. I may use it myself.

                                  Is this one of Gary Smith's Xtras? If so why there is no link to it on
                                  the Magic Modules website?

                                  Seems like an excellent candidate for The Mile-High Table O'Products
                                  too. http://www.updatestage.com/MileHighTableOfProducts/products.shtml
                                  • 14. Re: Couple of Scripting questions
                                    Level 7
                                    Yes, Gary wrote it, and it used to be on his site, but he removed it a
                                    while ago. I do not know why. Luckily, it was mirrored at mediamacros.
                                    • 15. Re: Couple of Scripting questions
                                      ytlevine Level 1
                                      Thanks to everyone for all the help.
                                      Dave, I am not discouraged - I am enjoying this, and like challenges. I am also learning the program better and better with each new suggestion I get.

                                      >I assume you intend n to be a global variable. Yes this will work, but
                                      >an even better way is for both the list and the counter to be custom
                                      >sprite properties that you define. This is another "intermediate" level
                                      >programming technique (object oriented programming) that you will want
                                      >to master at some point.

                                      I don't really understand what you mean. How would I do this, or get info about how to do it?

                                      Next, Mike:
                                      >My sample was just a repeat loop showing you how you can use a variable
                                      >to find the items in the list.

                                      And what would this variable include - the number of items? (Sorry, I am not by my computer with Director now).
                                      And if I need to tell it to go to the next item, the n=n+1 and getAt(mylist, n) will work, or you're suggesting a better
                                      (or different) way to do it?
                                      Thanks everyone for the help and patience!!
                                      • 16. Re: Couple of Scripting questions
                                        Level 7
                                        In my example, i is a variable. It is in a repeat loop. Look up repeat
                                        in the help file if you don't know what a repeat loop is. It counts from
                                        one number to another. In my example, it counts from 1 to <how ever
                                        many items are in the list>... in my example, there are 2 items in the
                                        list, so it counts from 1 to 2.

                                        You can reference the list using brackets instead of getAt (though getAt
                                        is fine if you like it).

                                        aList=["something","somethingElse","other"]

                                        put aList[1]
                                        -- "something"

                                        x=1
                                        put aList[x]
                                        -- "something"

                                        x=x+1
                                        put aList[x]
                                        -- "somethingElse"

                                        x=x+1
                                        put aList[x]
                                        --"other"
                                        • 17. Re: Couple of Scripting questions
                                          ytlevine Level 1
                                          With the drag and drop xtra, does anyone know if it was included in another xtra, or just removed from the site?
                                          • 18. Re: Couple of Scripting questions
                                            Level 7
                                            ytlevine wrote:
                                            > With the drag and drop xtra, does anyone know if it was included in another xtra, or just removed from the site?

                                            It is downloadable here http://www.mediamacros.com/files/dropFile.zip
                                            • 19. Re: Couple of Scripting questions
                                              ytlevine Level 1
                                              I got it there - just couldn't find any more info than that.
                                              One more question - is there any way to make a trial of your project(or), and then allow the user to enter a serial to make it a full version? and I assume that to make it expire at a certain date, you tell it to get the date, and if the current date is more than the expiration date, tell it to go to a certain marker, where you tell them that it expired.
                                              • 20. Re: Couple of Scripting questions
                                                Level 7
                                                Did you have a question about how to use it? There really isn't much to
                                                it, did you see the read me file? I just saw it for the first time
                                                myself, but I can probably help you. The creator seems to have dropped
                                                it from his website, not sure if you will get any info from there.

                                                About your trial version question, there are some basic things you can
                                                do for this, but they are easy to get around if the person is trying
                                                really wants to. For 'serious' software licensing systems see the
                                                "Protection" section on this page
                                                http://www.updatestage.com/MileHighTableOfProducts/products.shtml
                                                • 21. Couple of Scripting questions
                                                  ytlevine Level 1
                                                  I didn't try it yet. I got some info from Gary (the author).
                                                  With the protection, it was just an idea - it's not worth it to buy an xtra just for that.
                                                  I just thought that if there is a free xtra, or a way to do it in Lingo, it would be nice.
                                                  • 22. Re: Couple of Scripting questions
                                                    Level 7
                                                    ytlevine wrote:
                                                    > I didn't try it yet. I got some info from Gary (the author).
                                                    >

                                                    So you got support in less than 24 hours for a free product that is no
                                                    longer officially available. Now that's 'customer service'!
                                                    • 23. Re: Couple of Scripting questions
                                                      ytlevine Level 1
                                                      I was trying to use that DropFile Xtra, and have no idea how to use it.
                                                      Can anyone help me out?
                                                      Specifically, I read the readme, but I don't know what to put under "on dropfile" to tell it to add the file into a variable or list.
                                                      Thanks.
                                                      • 24. Re: Couple of Scripting questions
                                                        Level 7
                                                        on startMovie
                                                        startDropFile()
                                                        end

                                                        on stopMovie
                                                        closeDropFile()
                                                        end

                                                        on dropFile
                                                        set fileList = getDroppedFiles()
                                                        put "These files were dropped:" && fileList

                                                        set folderList = getDroppedFolders()
                                                        put "These folders were dropped:" && folderList
                                                        end
                                                        • 25. Re: Couple of Scripting questions
                                                          Level 7
                                                          What you put under the "on dropFile" handler totally depends on what you
                                                          want it to do. Only you can answer that question.

                                                          The code shows how to assign the list of files to a variable

                                                          set fileList = getDroppedFiles()

                                                          getDroppedFiles() already returns a list. If fileList is declared as a
                                                          global variable, then the list of files dropped will be available to
                                                          other handlers as needed. If it is not declared as a global, the it is
                                                          only available to the "on dropFile" handler and will be discarded once
                                                          the handler completes (such as in the example").

                                                          Can you elaborate on what you want it to do.



                                                          ytlevine wrote:
                                                          > I was trying to use that DropFile Xtra, and have no idea how to use it.
                                                          > Can anyone help me out?
                                                          > Specifically, I read the readme, but I don't know what to put under "on
                                                          > dropfile" to tell it to add the file into a variable or list.
                                                          > Thanks.
                                                          >
                                                          • 26. Re: Couple of Scripting questions
                                                            ytlevine Level 1
                                                            I want to add all the dropped files into a list (or a variable, but I think I will probably use a list) that I can use to do other things with.
                                                            • 27. Re: Couple of Scripting questions
                                                              Level 7
                                                              Like Dave (and Mike) already said, that's exactly what it does. Did you
                                                              try Mike's code? It will show you, in your message window (Ctrl + M) the
                                                              list of files and folders you dropped on your stage.

                                                              What part of this are you having trouble with?
                                                              • 28. Re: Couple of Scripting questions
                                                                ytlevine Level 1
                                                                Sorry - I am just learning how to use lists, and I am confused how to put the drop file xtra and lists together.
                                                                If I have an existing list , e.g. "addedfiles", how would I tell it to add all files dropped to the list "addedfiles" ?
                                                                And I want that I am not limited to adding things to the list by dropping them on the stage - that I can also add items other ways.
                                                                Thanks for all the help.
                                                                • 29. Re: Couple of Scripting questions
                                                                  Level 7
                                                                  Something like this should do it. Note I changed your list variable to
                                                                  gAddedfiles. It doesn't really matter, but for clarity the convention is
                                                                  for global variables start with a little g.

                                                                  --
                                                                  global gAddedfiles

                                                                  on startMovie
                                                                  startDropFile()
                                                                  end

                                                                  on stopMovie
                                                                  closeDropFile()
                                                                  end

                                                                  on dropFile
                                                                  fileList = getDroppedFiles()
                                                                  repeat with i in fileList
                                                                  gAddedfiles.add(i)
                                                                  end repeat
                                                                  end
                                                                  • 30. Re: Couple of Scripting questions
                                                                    ytlevine Level 1
                                                                    Thanks for the help.
                                                                    I will try this, though I am not by my computer with Director, so I can not try it now.
                                                                    Two question: Where do I put this code?
                                                                    Also, what does "i" do? I've seen a lot of people use it, and I have no idea how. Can you help me with this?
                                                                    Thanks a lot!!
                                                                    • 31. Re: Couple of Scripting questions
                                                                      Level 7
                                                                      Where do I put this code?

                                                                      In a movie script.

                                                                      Also, what does "i" do?

                                                                      It is a variable. There is nothing special about using i, you could use
                                                                      j, k, dave, ytlevine, counter, x3, etc. The use of i as a repeat loop
                                                                      control variable is just one of those long standing traditions.

                                                                      So in this example, let's say you drop 3 files onto the program. This
                                                                      triggers the dropFile event. When an event occurs, Director looks for a
                                                                      handler for that event. Since you made a handler named dropFile, the
                                                                      code executes.

                                                                      First it calls the getDroppedFiles() function and assigns the list to a
                                                                      variable called fileList

                                                                      fileList = getDroppedFiles()

                                                                      So fileList might look something like this (just as an example)

                                                                      ["c:\file1name.ppt","c:\file2Name.doc", "c:\file3Name.xls"]

                                                                      repeat with i in fileList takes each item in the list, one at a time and
                                                                      assigns it to i. So on the first iteration of the loop i =
                                                                      "c:\file1Name.ppt"

                                                                      "gAddedfiles.add(i) would become gAddedfiles.add("c:\file1Name.ppt")
                                                                      which adds the fileName to the global variable gAddedfiles

                                                                      That's the end of the loop, so it starts again, this time with i =
                                                                      "c:\file2Name.doc", which again gets added to the global variable.

                                                                      Once the code has gone through all of the file names, the repeat loop is
                                                                      done and the program flows exits the loop. Do you see the usefulness of
                                                                      this? It doesn't matter if the user drops 1 file, 10 files, or 100
                                                                      files, the repeat loop does the work of adding each one to you global
                                                                      variable.

                                                                      Now, what your program does in response to the files added to the global
                                                                      variable gAddedfiles, well that's up to you.


                                                                      • 32. Re: Couple of Scripting questions
                                                                        ytlevine Level 1
                                                                        Thanks, Dave. I really appreciate your help.
                                                                        I will try your suggestions, and I really appreciate your patience, explaining everything clearly.
                                                                        And thanks to everyone else who also helped!!
                                                                        I will be busy for a while...
                                                                        I have a lot more reading to do...
                                                                        Be well.