17 Replies Latest reply on Sep 3, 2006 7:54 PM by Opera Rat

    concatenation confusion

    Opera Rat Level 1
      I have some properties set up for a multiple choice question. Everything is working (I think) except for the go to marker portion of the script. On each sprite (answer) sits the script. When it's clicked on the script determins if it is a correct answer or not and collects the number of the question and moves to a marker called XXerror or XXcorrect (XX is the question number which is collected in pAnswer. So I want to add to pAnswer the error or correct. Did I do this correctly?
      For example, the question is 2q2. So the property of pInquiryNumber is 2q2 and after determining if it is correct or not (from a boolean property pAnwer) it assigns tReponse as 2q2error or 2q2correct. Right now it goes to 2q2correct no matter what.

      if pAnswer = FALSE then
      tResponse = pInquiryNumber&"error"
      else
      tResponse = pInquiryNumber&"correct"
      end if

      sound(3).play(member(pPlayResponse))
      go to marker(tResponse)
      cursor -1

      end
        • 1. Re: concatenation confusion
          Level 7
          I;m not sure why you named this question about concatenation. That part
          seems to be working as it should. The problem you are having is that
          pAnswer is always coming up as TRUE. Some part of the code that you did
          not post (the part where it figures out if the answer is correct or not)
          seems to be returning Correct all the time (if indeed it is always
          jumping to the 'correct' frame). Look into the script that generates
          the value of pAnswer and I suspect you'll find the problem.
          • 2. concatenation confusion
            Opera Rat Level 1
            Thanks Mike. But this IS the part of the script that determines if pAnswer is true or not. pAnswer is a property that is set at the time you assign this script. - a checkbox, true or false. I wasn't sure if the concatenation was correct - I have other properties in the script where things are added to the property (like score keeping) and I wasn't sure this was the proper methoed of doing this. It's good to know I did something right. This is the relavent portion of the script. How am I not determining if pAnswer is true or false?

            All the global variables are the different categories that an answer keeps track of (pCategory). I don't know how to work well with lists. But I bet there is a way to have the category part of the property list show you the full text of sr (score reading), ta (tonal analysis) and then look at some other list and get the abbreviations. - A database. Is does get confusing trying to remember what these little abbreviations mean (and there are going to be 20 more!)

            global sr, ta, tl, fe, sdi, mii, ma, hii, sti, tha, sffr, tr, ca, fs, scr

            property pInquiryNumber, pAnswer, pShowAnswer, pCategory, pPlayResponse

            on getPropertyDescriptionList me
            list = [:]
            addProp list, #pInquiryNumber, [#comment: "Inquiry Number", \
            #format: #string, #default: VOID]
            addProp list, #pAnswer, [#comment: "Answer:", \
            #format: #boolean, #default: 0]
            addProp list, #pShowAnswer, [#comment: "Channel of Answer:", \
            #format: #integer, #range: [12, 13, 14, 15, 16, 17, 18, 19], #default: VOID]
            addProp list, #pCategory, [#comment: "Category:", \
            #format: #string, #range: ["sr", "ta", "tl", "fe", "sdi", "mii", "hii", "sti", \
            "tha", "sffr", "tr", "ca", "fs", "scr"], #default: VOID]
            addProp list, #pPlayResponse, [#comment: "Play Voice Over", \
            #format: #sound, #default: ""]
            return list
            end

            on mouseUp me
            HideAnswers

            -- count how many times the question was attempted. First add times to the question number (ex. 2q2times) the add
            -- 1 to XXtimes

            AnswerAttempts = pInquiryNumber&"times"
            set AnswerAttempts = AnswerAttempts + 1

            -- add or subtract a point to the proper answer category

            if pAnswer = 0 then
            set pCategory = pCategory - 1
            else
            set pCategory = pCategory + 1
            end if

            -- Show and Hear Answer
            sprite(pShowAnswer).visible = TRUE

            -- Determine if answer is correct or error then go to the proper marker by getting the value of pAnswer

            if pAnswer = 0 then
            tResponse = pInquiryNumber&"error"
            else
            tResponse = pInquiryNumber&"correct"
            end if

            sound(3).play(member(pPlayResponse))
            go to marker(tResponse)
            cursor -1

            end

            So the way this works is each answer (sprite) in a multiple choice question gets this script. It keeps score, moves to the appropriate marker and plays the appropriate voice over. If the tResponse is always coming TRUE then I guess the part of my script that is keeping score isn't working. Text How am I not determining if pAnswer is true or false?
            • 3. Re: concatenation confusion
              Level 7
              OK, well, you have a lot of places where you check if pAnswer is true or
              false, but there is nothing that sets it to be true or false. It would
              be something like

              if sprite("checkbox").member.selected=True then
              pAnswer=True
              else
              pAnswer=False
              end if

              In your script, you are setting pAnswer in your GPDL dialog.

              addProp list, #pAnswer, [#comment: "Answer:", \
              #format: #boolean, #default: 0]

              I assume that you set it to True, thus it always sees the answer as
              being true. You need something that will set it false if the answer is
              chosen incorrectly.
              • 4. Re: concatenation confusion
                Opera Rat Level 1
                I thought that if I check the box for pAnswer when I set the property (when the script is dragged over the sprite originally) then the answer would be True and if I didn't check the box the answer would be false. I don't understand if sprite("checkbox").member.selected=True then. What checkbox. The only checkbox there is is the one when you set the properties. Can't I do something like: if pAnswer then do this...else if not pAnswer then do that. It doens't work, but it seems logical.
                • 5. Re: concatenation confusion
                  Level 7
                  I just made that checkbox thing up as an example where it is possible
                  for the answer to be true if it is checked and false it is not. I have
                  no idea how your quiz is setup, so I'm just making up things in order to
                  explain what I'm talking about.

                  If you have that behaviour you posted on a sprite, and you set the
                  pAnswer option in the GPDL to True, then when it is clicked, it will
                  always go to the pInquiryNumber&"correct" frame. If you set it to
                  False, then it will always go to the pInquiryNumber&"error" frame. Is
                  that what you want it to do? Is that not what is happening? It is
                  working for me when I try it.

                  In the GPDL popup, I put for example, 1 in the Inquiry Number, and set
                  Answer=true (checked).

                  When I click on that sprite, it jumps to the "1Correct" frame.

                  If I change the GPDL option so that Answer=false (unchecked), then when
                  I click on it, it jumps to the "1Error" frame.

                  It doesn't work if you change the GPDL option while the program is
                  running, since the GPDL options are not reset until you hit Play again,
                  that is the only thing I can think of that would cause what I think you
                  are saying.
                  • 6. Re: concatenation confusion
                    Opera Rat Level 1
                    Yes, I did it.

                    if pAnswer = TRUE then
                    tResponse = pInquiryNumber&"correct"
                    else if pAnswer = not TRUE then
                    tResponse = pInquiryNumber&"error"

                    BUT I have noticed a new problem with the keeping count of the number of answer attempts portion of the script.

                    AnswerAttempts = pInquiryNumber&"times"
                    set AnswerAttempts = AnswerAttempts + 1

                    Each time the user gets the answer wrong pInquiryNumber gets times appended to it. So if pInquiryNumber property was set for CP2q2 (I've changed my numbering method as it doesn't like variables that begin with numbers) It becomes CP2q2times and that variable gets a one added to it. So if the user takes 4 tries to anwer the question before getting it correct CP2q2times would equal 4. See code above. Now how can I turn AnswerAttempts back into the global variable CP2q2times. In otherwords how can I now create a global variable on the fly?

                    Then the score keeping portion is similar:

                    -- add or subtract a point to the proper answer category
                    if pAnswer = TRUE then
                    set pCategory = pCategory + 1
                    else if pAnswer = not TRUE then
                    set pCategory = pCategory - 1
                    end if

                    This global variable is set in a list at the top of the script. Is this the correct way to achieve this example:
                    pCategory was set in the GETProp list for this particular answer to sr. Many answers use the category sr. So that by the time the user gets to this question sr could equal 9 (or -9 if they're not learning anything). Will my code add or subtract 1 to/from to the global variable sr?
                    • 7. Re: concatenation confusion
                      Level 7
                      When you do this, it is not doing what you think it is doing:

                      AnswerAttempts = pInquiryNumber&"times"
                      set AnswerAttempts = AnswerAttempts + 1

                      The 1st line is setting the value of AnswerAttempts to "CP2q2times".
                      That is a string. The 2nd line is trying to add one to it. It is like
                      trying to do this:

                      "CP2q2times"+1

                      That doesn't make sense. You can't add any number to a string.

                      Just make a property that counts the number of times it has been attempted.

                      property pAttempts

                      ... somewhere in the on mouseUp handler...
                      if voidP(pAttempts) then
                      pAttempts=1
                      else
                      pAttempts=pAttempts+1
                      end if


                      That will make it start off with 1 and count up on each subsequent mouseUp.

                      ----

                      This one has the same issue as the last email I posted. If you set
                      pAnswer to True, then pCategory will ALWAYS be increased by one on each
                      mouseUp. If you set it to False, then it will be decreased by one. It


                      -- add or subtract a point to the proper answer category
                      if pAnswer = TRUE then
                      set pCategory = pCategory + 1
                      else if pAnswer = not TRUE then
                      set pCategory = pCategory - 1
                      end if

                      I don't see any references to sr in this script, so I don't see why sr
                      should be incremented or decremented ever as a result of this script.
                      If you want it to be adjusted, then explicitly set it

                      If you are trying to increase sr if you get the answer right and
                      decrement it if you get it wrong, then it would be something like

                      if pAnswer=True then
                      sr=sr+1
                      else
                      sr=sr-1
                      end if

                      Since you have this same if..then statement elsewhere, you could combine
                      them all into one:

                      if pAnswer=True then
                      sr=sr+1
                      pCategory=pCategory+1
                      tResponse = pInquiryNumber&"correct"
                      else
                      sr=sr-1
                      pCategory=pCategory-1
                      tResponse = pInquiryNumber&"error"
                      end if
                      • 8. Re: concatenation confusion
                        Opera Rat Level 1
                        Thanks again. I'm really trying to get this Object Oriented Programming thing down.

                        Your pAttempts will work if pAttempts represents concatenated CP2q2times as a global variable.

                        I do want CP2q2times to become a global variable and get 1 added to it each time. This is my latest attempt, yet I know something is missing, but what?

                        AnswerAttempts = "global variable" && pInquiryNumber & "times" & RETURN
                        set AnswerAttempts = AnswerAttempts + 1

                        So the string CP2q2times need to turn into a global variable and then each time an answer to this particular question (CP2q2) is clicked on CP2q2times will go up. But let's say this works the first time the user gets the answer wrong and then the try again. If it creates another global variable with the same name would it restart the count again?

                        Is this even possible? It would probably be easier to just do all the scripts for each answer to each question manually (200 questions x 4 answers = 800 scripts instead of 1).

                        I'll deal with the score keeping part after I get this attempt count thing right, as it is dealing with the same issue. pCategory is a list of global variables - hmmm is there a #format for that? pCategory was set to sr when I dragged the script onto the sprite. sr is a global variable (see very top of script) so I need sr or whatever category pCategory was set to keep track of a number and I will look at sr or tl or whatever whenever I want to see my score.

                        This is sooo frustrating!!! Does it ever get easier? I couldn't do any of this without you guys.
                        • 9. Re: concatenation confusion
                          Level 7
                          I don't think you are going to get it to work that way. You cant just
                          set a string equal to the text "global variable" and expect it to be
                          one. It just sets the text to a string of characters... "global
                          variable CP2q2Times". Perhaps what you want it to use a property list.
                          Define a global variable something like gNumTimes.

                          gNumTimes=[:]

                          That makes it a blank property list. You can add properties like this

                          gNumTimes.setAProp(#CP2q1Times,1)

                          You can add that string you were using before if you want like this:

                          gNumTImes.setAProp(symbol(pInquiryNumber&"Times"),23)

                          If you do all those commands, then look at the value of gNumTimes

                          put gNumTimes
                          -- [#CP2q1Times: 1, #CP2q2Times: 23]

                          You can set as many properties as you want this way, so each question or
                          each inquiry number can add itself into the list as it needs to.

                          You can retrieve the values like this:

                          put gNumTimes[#CP2q1Times]
                          -- 1

                          put gNumTimes[#CP2q2Times]
                          -- 23

                          to increment CP2q2Times, you can do this:

                          gNumTimes[#CP2q2Times]= gNumTimes[#CP2q2Times]+1

                          The property lists are very powerful, and that seems to be what you are
                          after. Check out the help file for property lists, setAProp, addProp,
                          deleteProp, and setPropAt. Those are the important commands.

                          Also, use the Object Inspector. It helps a lot with big property lists.
                          Put gNumTimes in the Property Inspector and watch how the values show
                          up in there when you do the commands i listed above.
                          • 10. Re: concatenation confusion
                            Opera Rat Level 1
                            Yes, I read something on a list like this, but I am still afraid of property lists. Afraid that I'm really going in over my head. I understand from your example how to generate and add a property. But what if I had this on each answer for question CP2q2, would it create 4 properties CP2q2 if the user had to click on each of the 4 answers for this question or would I be ok?
                            New questions to this new and frightening endevour:

                            1. Where do I create this list? In each of the scripts, a movie script? Is it global?
                            2. If it is in a movie script (which seems to make sense) and then I add my new property to the list (on each answer sprite?) how do I deal with that XX number.

                            gNumTImes.setAProp(symbol(pInquiryNumber&"Times"),XX)

                            The first time it would be 1 and then I could add using:

                            hmmm I don't know. Because of the way I have it set up now I can't tell it
                            gNumTimes[#CP2q2Times]= gNumTimes[#CP2q2Times]+1 because it has to create the string CP2q2Times within the same script. How would I
                            gNumTimes[#concatenatedString]=gNumTimes[#concatenatedString]+1

                            Maybe I should just create the propery list in a movie script and add all the properties to it at one time. Then within the question I can have another propery pAttempts and when assigning this script to the sprite. Type in the string CP2q2times or whatever and then

                            gNumTimes[#pAttempts]= gNumTimes[#pAttempts]+1

                            Oh, I'm sure that won't work!! Because pAttempts isn't in the list! O.K. I have to give up on this for a while. I'm not making sense anymore. I have been working on nothing but this all day (and the glowy sprite thing which is also giving me grief. I've decided to go with an animated gif that I can set to loop once, I hope).

                            The more I work on this, the more I get lost.
                            • 11. Re: concatenation confusion
                              Level 7
                              In your sprite behaviour, on beginSprite, you instantiate the list and
                              the property for the question at hand (starting at 0). Then, on
                              mouseUp, you increase it

                              global gNumTimes

                              on beginSprite me
                              --start the list if it isn't there already
                              if voidP(gNumTimes) then gNumTimes=[:]

                              --set this property to 0
                              gNumTimes.setAProp(symbol(pInquiryNumber&"Times"),0)
                              end

                              on mouseUp me
                              --figure out what it is currently set to
                              lastAttempt=gNumTimes[symbol(pInquiryNumber&"Times"]

                              --increment it by 1
                              thisAttempt=lastAttempt+1

                              --set the variable to the new value
                              gNumTimes.setAProp(symbol(pInquiryNumber&"Times"),thisAttempt)

                              --all the rest of your code

                              end


                              The beauty of this approach is that you will have other sprites that
                              have different pInquiryNumbers (one for each question or answer, I'd
                              think), and this will nicely add a new property when it is needed. The
                              same behaviour can go on each sprite and everything should work nicely.
                              • 12. Re: concatenation confusion
                                Opera Rat Level 1
                                Thanks. Without your help I'd have to be institutionalized. It looks good. The only thing that may be a problem is

                                --set this property to 0
                                gNumTimes.setAProp(symbol(pInquiryNumber&"Times"),0)
                                end

                                Now if this is on each answer sprite and they click on two answers would the property get set back to zero? and then 1 added on the mouseclick or does it recognize that that property already exists in the list and is greater than zero wouldn't reset it back to zero. Remember this script goes on each answer for say, CP2q2.

                                Nothing is easy. Animated gifs just keep repeating. I want it to play once!
                                • 13. Re: concatenation confusion
                                  Level 7
                                  That line is in beginSprite, so it only happens when the sprite 1st
                                  shows up, not when it is clicked. It doesn't matter if it is set to 0
                                  multiple times. The point is, until one of them gets clicked, it will
                                  be zero. That is the difference between using setAProp and addProp, by
                                  the way. If you use addProp instead, then each time it shows up, it
                                  will add another property with the same prop name. That is what you do
                                  not want. By using setAProp, each one will instantiate the value as
                                  zero. Then if you click any of them, it will increment the counter by one.
                                  • 14. Re: concatenation confusion
                                    Opera Rat Level 1
                                    You are right Mike. I viewed what was happening in the message window and it would go from zero to one. Yea!! BUT I wasn't clear on why I was concerned about it resetting to zero. After choosing a wrong answer you are thrown to a frame that plays the wrong answer and perhaps a helpful animation, then YOU RETURN to the question and thus on beginSprite happens again. I have to figure out how to use the object inspector. So I guess there needs to be something that knows that this is not the first attempt on this question so don't setProp. Or is there a way to check first to see if the gNumTimes.setAProp(symbol(pInquiryNumber&"Times"),0) exists in the list and if so do nothing?
                                    • 15. Re: concatenation confusion
                                      Opera Rat Level 1
                                      All done!!! Thanks for you help with the counting portion. I'll bang my head against the wall for a few hours and see if the score keeping part is working. If not, I'LL BE BACK. Here is what I did

                                      on beginSprite me
                                      --start the list if it isn't there already
                                      if voidP(gNumTimes) then gNumTimes=[:]

                                      --add property to list if it isn't there
                                      if gNumTimes[symbol(pInquiryNumber&"Times")] >= 1 then
                                      else
                                      gNumTimes.setAProp(symbol(pInquiryNumber&"Times"),0)
                                      end if
                                      end
                                      • 16. Re: concatenation confusion
                                        jonnno Level 1
                                        Hi Opera Rat,

                                        Firstly, let me say that what Mike Blaustein is telling you is definitely the right kind of approach for what you're trying to achieve. As i'm sure you know, you will be far better off in the long run by getting your head round parent scripts etal.

                                        However, sometimes, and in the right kind of situation, it can be very handy to create lingo on the fly ~

                                        Director MX 2004 now supports Flash stylee javascript so Director developers can now make use of the eval function (which is what i think you thought the lingo set function was going to do for you)

                                        Also you might want to check this little director app out. It dynamically creates a lingo global variable and a handler that increments and displays the value of the global. have fun!



                                        • 17. Re: concatenation confusion
                                          Opera Rat Level 1
                                          Thank you. I thought that something like that was possible, though not as clean as a list. Now, I'm trying to figure out this score keeping part. When I first started working on this project I wrote a script for each questions answer. That was actually not as stupid as it sounds. As the writer had a different set of criteria for each question. Some had 2 answers, some had a different response for each wrong answer and others counted the attempts you made and responded according to the attempt number, there were more. It was all over the place. Then he got tired and now most questions are set up to have 1 response to each answer. So in each script I would put the category of the answer (some answer to the same question have different categories, meaning you didn't understand a particular aspect of the question). This is what I did:

                                          on mouseUp me
                                          global ma
                                          set ma = ma - 1
                                          sprite(13).visible = false
                                          sprite(14).visible = false
                                          sprite(15).visible = false
                                          sound(3).play(member("error7a"))
                                          go to "q7error"
                                          cursor -1
                                          end

                                          (Not the bold face, of course), So EACH answer that had a different reponse got a script similar to this. This script keeps a running tally of ma. So if the user scored after this question was ma = -1 the next question with an ma answer would just add to that. I'm thinking that I need to create a list (gCatList) - probably in a movie script with onStartMovie. And define all the categories in this list and set them to 0. Then I need to take pCategory and:

                                          lastScore=gCatList[symbol(pCategory]

                                          --increment it by 1 or subtract depending on pAnswer being true or not
                                          --I'll just show if it is true here.
                                          currentScore=lastScore+1

                                          --set the variable to the new value
                                          gNumTimes.setAProp(symbol(pCategory)currentScore)

                                          Am I on the right track or will this lead me into HELL?