2 Replies Latest reply on Nov 15, 2006 3:54 AM by Newsgroup_User

    help resetting a global variable

    curlimacue
      I have a survey. At the beginning, I declare global variable called gAllAnswers. As I go through survey, the answers (radio button values) are appended and added to a string in this global gAllAnswers. Then at the very end I write this data out to a txt file using FileIO.
      My problem is, as more than one user goes through the survey, the global variable is retaining all the users data. For ex, the first time thru it puts user 1's data. Then second time user 1's data is already there, and then it adds on user 1's data again (because it persists) as well as user 2's data --So I have user 1's data twice which I don't need.
      How can I reset this global variable (I don't want to clear it, because I still need to use it)?
      I tried putting on a mouseUp event at end of my survey a
      set gAllAnswers = ""
      but that didn't work.

      Here are my scripts:
      MOVIE SCRIPT:
      global gSectionList, gThisSectionList

      on startMovie
      global gAllAnswers
      set gAllAnswers = []
      gSectionList = ["CB","CW","S","G"]


      end startMovie

      -------
      THEN ON MY Q'S:
      append (gAllAnswers, member ("color_q").text)

      put string(gAllAnswers) into field "AllAnswersRotated field"

      THEN ON THE LAST BUTTON OF THE SURVEY:
      set scribe to new (xtra "FileIO") --"scribe" is just the name of the object
      openFile (scribe, "data.txt", 0) --CHANGE RESULTS FILE NAME HERE, must open it to direct where to write
      setposition (scribe, (getLength(scribe))) --must go to the end of the file so you don't overwrite anything there
      writeString (scribe, the text of field "AllAnswersRotated field") --send the whole shabang at once
      closeFile (scribe) --close is nice to do, clean up after itself...

      I appreciate any hints/direction on how to reset my gAllAnswers so that when a new user takes the survey it will only record their data at the end (then movie loops back to beg for next user)
      Thank you.
        • 1. Re: help resetting a global variable
          Level 7
          You'll need some sort of handler that initiates a new survey. If you
          already do, that's the place to reinitialize your global. If you don't, you
          need it. Right now, how do you differentiate between users? How does Lingo
          know when a new surveyor is inputting data?


          "curlimacue" <webforumsuser@macromedia.com> wrote in message
          news:ejef4v$l2h$1@forums.macromedia.com...
          >I have a survey. At the beginning, I declare global variable called
          > gAllAnswers. As I go through survey, the answers (radio button values) are
          > appended and added to a string in this global gAllAnswers. Then at the
          > very
          > end I write this data out to a txt file using FileIO.
          > My problem is, as more than one user goes through the survey, the global
          > variable is retaining all the users data. For ex, the first time thru it
          > puts
          > user 1's data. Then second time user 1's data is already there, and then
          > it
          > adds on user 1's data again (because it persists) as well as user 2's
          > data --So
          > I have user 1's data twice which I don't need.
          > How can I reset this global variable (I don't want to clear it, because I
          > still need to use it)?
          > I tried putting on a mouseUp event at end of my survey a
          > set gAllAnswers = ""
          > but that didn't work.
          > I appreciate any hints/direction.
          > Thank you.
          >


          • 2. Re: help resetting a global variable
            Level 7
            I'm guessing that the 'end' of the project as far as a single user is
            concerned is when their data is written out to a file, right? If so,
            then after the data is no longer needed in memory (i.e. after it has
            been written out to a file), then set your variable to VOID (or whatever
            the starting value should be).