9 Replies Latest reply on Mar 6, 2007 11:20 AM by Newsgroup_User

    Writing a lingo script from an Interface

    wgb14 Level 1
      Hi all,

      I wonder if there is any way to write a Lingo Script (movie) from scratch from an interface in director. In particular, I want to create an interface where when i will input a question + an answer and press the button next a particular line of code will be wirtten. For example:

      On answergeneration
      if the text of member ("Question") = "Yes" then
      do this
      end

      Is there any way to write the code from scratch by simply using the next button?

      Many thnaks
        • 1. Re: Writing a lingo script from an Interface
          Level 7
          "wgb14" <webforumsuser@macromedia.com> posted in
          macromedia.director.lingo:

          > I wonder if there is any way to write a Lingo Script (movie) from
          > scratch from
          > an interface in director. In particular, I want to create an interface
          > where when i will input a question + an answer and press the button next
          > a particular line of code will be wirtten.

          Possibly.

          Check out new() for creating a new #script member if you don't have a
          placeholder already handy. Also, setting the scriptType of the member to
          #movie.

          Then you should be able to set the scriptText of the member to your string.

          I have no idea how well this works from a run-time environment since Director
          hasn't had a chance to compile the script to byteCode (as it does during
          Publish).

          Give it a try in a simple test movie before getting to deep into it.


          --
          Mark A. Boyd
          Keep-On-Learnin' :)
          • 2. Re: Writing a lingo script from an Interface
            wgb14 Level 1
            Hi

            Thanks for the reply... this is what i have so far...

            on mousedown
            set customscript = new(#script)
            member(CustomScript).Scripttext = the text of member "Script"

            end

            the text of member script is the following:

            (the text of member "current_script" = "&scriptname&"):


            My problem is as follows. I am not sure how to create new lines with the above code every time that my user will click next and give the value for the variable scriptname in a MIAW. For example

            User click next -> A MIAW comes up and asks him to input the value for scriptname -> the code that should be written is as follows:

            (the text of member "current_script" = "1.hap"):
            tell dialogue to 1.hap

            the second time that my user will click next and will give the value for scriptname -> the code should be as follows:

            (the text of member "current_script" = "2.hap"):
            tell dialogue to 2.hap

            and so on

            any ideas?
            • 3. Re: Writing a lingo script from an Interface
              Level 7
              "wgb14" <webforumsuser@macromedia.com> posted in
              macromedia.director.lingo:

              > on mousedown
              > set customscript = new(#script)
              > member(CustomScript).Scripttext = the text of member "Script"
              > end

              If you never erase that member, you'll end up with multiple unnamed script
              members. If you want to use the same script member, don't create it in code.
              Just create it once during authoring, give it a name, and refer to it by that
              member name.

              > the text of member script is the following:
              >
              > (the text of member "current_script" = "&scriptname&"):

              All lingo must be in a handler defined with the 'on' and 'end' keywords.
              Setting the scriptText of a script member to a single line just won't work
              since there's no handler name to execute. You would need to create the entire
              script, including the on handlerName, the lines of code, and the 'end' with
              RETURNs in appropriate places. Then you would execute it in a line of code as
              (from this example) handlerName. Something like the following where I've
              created a handler named doIt

              global scriptname -- global since I don't know where you're getting it
              on mouseUp me
              scr = "on doIt" &RETURN
              scr = scr &scriptname &".hap" &RETURN
              scr = scr &"end"
              member("dynamicScript").scriptText = scr
              doIt
              end

              That seems like a very convoluted system, though there may be a good reason
              for it. What if a user enters a number representing a handler that doesn't
              exist? Say, 2147483647. Do you have a handler (object?) named 2147483647.hap?

              [snip]

              I'm really not catching the concept here. You mention the text of member
              script containing the text of member "current_script" equal to a supposed
              variable enclosed in quotes (thus making it a string, not a variable) and
              wrapped in ampersands - which you later refer to as a variable named
              scriptname without ampersands. All somehow related to the new script
              member(customscript). *I am thoroughly confused*.

              What is member("current_script")?

              How does the user input the value for scriptname? Do they type a 1, 2, 77, or
              whatever into a #field or #text member? Then a mouse click is supposed to
              execute a handler in dialog (is dialog a MIAW?) named as 1.hap, 2.hap, ...
              according to what they typed?

              Where does &scriptname& come into the picture? Is it related any of the
              above?

              /***/

              Are you sure you need to use self-modifying code here? Maybe you can use
              parameters instead.

              -- PSEUDO CODE FOLLOWS

              -- movie script in (I assume) window "dialog"
              on hap (aValue)
              case aValue of
              1: doThis
              2: doThat
              3: doOther
              otherWise
              alert("Please provide a value")
              end case
              end

              -- behavior script
              on mouseUp me
              aVal = <get the user's input value from somewhere?>
              tell window("dialog") to hap(aVal)
              end

              /***/

              Or are you incrementing a variable for each mouse click on the "next" buton?
              First is supposed to execute 1.hap, 2nd time it executes 2.hap, etc.

              If so, still no need for modifying code at run-time. Assuming a similar movie
              script shown above:

              property pClicks
              on mouseUp me
              pClicks = pClicks + 1
              tell window("dialog") to hap(pClicks)
              end

              /***/

              Let me know if I'm way off base here. If so, please explain in more details
              what you really want to happen.


              --
              Mark A. Boyd
              Keep-On-Learnin' :)
              • 4. Re: Writing a lingo script from an Interface
                Level 7
                Upon re-reading, I am even more dazed and confused (no I haven't hit the pub
                yet :)

                > tell dialogue to 1.hap

                I'm not on my dev machine, but can you even HAVE a handler name with periods
                in it? Or beginning with a number? Or named only as a number?

                What, exactly is 1.hap in your project?

                What, exactly is dialogue?


                --
                Mark A. Boyd
                Keep-On-Learnin' :)
                • 5. Re: Writing a lingo script from an Interface
                  wgb14 Level 1
                  Hi,

                  Apologies, the infrmation that i have provided are not sufficient... Well.. this is what i am trying to do. It is actually a question-answering tool for a system that i am developing:

                  Well,

                  Question:

                  Answer:

                  Next (next is a button)

                  Uppon hiting next i want a window to come up and ask the user ("Name of the answer script?). For example, if the answer script is 1.hap(hap is the file extension for a 3D charcter engine that i am using) the following must happen:

                  1) Create inside director a movie script with the following code:

                  (the text of member "current_script" = "X"): -- X should be the name of the script that my user will give in the window
                  tell dialogue to X --Again X should be the name of the script that my user will give, -- dialogue is a MIAW variable

                  I want the above code to be repated as many times as the user wants

                  Thanks
                  • 6. Re: Writing a lingo script from an Interface
                    wgb14 Level 1
                    To be more specific lets assume that my user enters the question: What can you tell me about Greece?

                    and the Answer: Greece is a country

                    Once he clicks next, a window must come up and ask the user "Name of the Answer Script?" Once the user will input the name then:

                    The application should write the corresponding Director movie script:

                    (the text of member "CurrentScript" = X): -- where x is the name of the script that my user will give
                    tell dialogue to X

                    Any ideas?

                    Many thanks
                    • 7. Writing a lingo script from an Interface
                      James Newton, ACP Level 3
                      Why do you want to create this as a set of scripts? Have you tried building your set of question-and-answers as a property list? See here for an example. You could create a generic set of behaviors that lets you play back the question and answers, rather than having a spaghetti sprawl of custom scripts. This separates the logic from the content, and leads to a project that is much easier to maintain.
                      • 8. Re: Writing a lingo script from an Interface
                        wgb14 Level 1
                        The reason for the scripts is that what i am bulding is supposed to be a tool that will make mylife less painful when writing the scripts necessary for my project. Scripts are unfortuntely necessary!!!
                        • 9. Re: Writing a lingo script from an Interface
                          Level 7
                          "wgb14" <webforumsuser@macromedia.com> posted in
                          macromedia.director.lingo:

                          > (next is a button)
                          >
                          > Uppon hiting next i want a window to come up and ask the user ("Name of
                          > the answer script?). For example, if the answer script is 1.hap(hap is
                          > the file extension for a 3D charcter engine that i am using) the
                          > following must happen:

                          OK, you can use Buddy API and its baPrompt() function for that. (See the "How
                          to Get a prompt in lingo" thread for other possibilities)

                          > 1) Create inside director a movie script with the following code:
                          >
                          > (the text of member "current_script" = "X"): -- X should be the name of
                          > the script that my user will give in the window
                          > tell dialogue to X --Again X should be the name of the script
                          > that my user will give, -- dialogue is a MIAW variable

                          You still have to create handlers. You simply cannot execute Lingo that does
                          not exist between the 'on <handlername>' and 'end' handler definition.

                          And now I've confirmed that you cannot have a handler named with a period or
                          starting with a number. So 'tell dialogue to 1.hap' will never work.

                          Otherwise, to me, 'name of a script' is simply a script member name as in
                          member("myScript") which could have any amount of code. And, of course, you
                          can't execute - or tell a window to execute - a member name.

                          Still, here's an untested snippet that might work. It assumes I've created a
                          #movie script member named "dynamicScript" during authoring.

                          -- PSEUDO CODE
                          on mouseUp me
                          -- x = baPrompt(see buddy api docs for parameters)
                          x = "1.hap" -- for testing purposes
                          scr = "on doIt" &RETURN
                          scr = scr &"member(" &QUOTE &"current_script" &QUOTE &" = " &x &RETURN
                          scr = scr &"tell dialgue to" &&x &RETURN
                          scr = scr &"end"
                          member("dynamicScript").scriptText = scr
                          end

                          Now if you open member "dynamicScript" in the script editor, it should look
                          pretty close to what you want.

                          > I want the above code to be repated as many times as the user wants

                          Oh. So it's going to create multiple script members with necessary
                          unique handler names? I suppose you could use a parent script or a global
                          variable to increment a number to ensure each handler has a unique name, ie:
                          doIt1, doIt2, doIt3, etc... (note number at end of handler name).

                          But then, how is any other code in the movie supposed to be aware that those
                          scripts were created?

                          Hopefully there's some information in here you can utilize to make your
                          script writing movie. Sounds as if you could end up spending more time
                          creating this movie than simply creating the scripts :)


                          --
                          Mark A. Boyd
                          Keep-On-Learnin' :)