4 Replies Latest reply on Mar 8, 2014 7:50 AM by jackblackweb

    Repeat With + Property List + leaderboard / rank of best scores

    MAC800

      Hello I have a List question

       

      I am stuck writing this line of code

       

      He is my project

      I need to "rank" in descending order 50 game contestants

       

      The names of the contestants are in fields "contestants1" to "contestants50"

      The scores of the contestants are in fields "score1" to "score50"

       

      A property list will have or be created ? Yes? No?

       

      Then that list will have to be sorted with "best score" to "lowest score" and the "contestant" name with the score in the list. Example if Brandon ends up being in 32nd place with 344 points  the list would have the player name and result.

       

      **I am familiar with max() however, that is only going to give me one result .. I need them reordered descending

       

      Lastly the really easy part the sorted list placed in a filed cast member "FinalResults"

       

      Example member("FinalResults").text = string(aList)

        • 1. Re: Repeat With + Property List + leaderboard / rank of best scores
          jackblackweb Level 1

          -- Message Window

           

          thisNumberList = ["5", "2", "1", "4", "3"]

          put thisNumberList

          -- ["5", "2", "1", "4", "3"]

           

          thisNumberList.sort()

          put thisNumberList

          -- ["1", "2", "3", "4", "5"]

           

          If more is needed let me know. Love writing code.

          Jack

          • 2. Re: Repeat With + Property List + leaderboard / rank of best scores
            MAC800 Level 1

            Hey thanks for the reply

             

            How would you go about sorting in descending order. "Sort" seems to order them ascending 

             

            Thanks

            • 3. Re: Repeat With + Property List + leaderboard / rank of best scores
              Dee McDee Level 2

              You would need to do something like this:

               

              on mouseUp me

               

                thisNumberList = ["5", "2", "1", "4", "3"]

                thisNumberList.sort()

               

                newNumberList = []

                repeat with i = thisNumberList.count() down to 1

                  newNumberList.add(thisNumberList[i])

                end repeat

               

                put newNumberList

               

              end mouseUp

               

              -- ["5", "4", "3", "2", "1"]

              • 4. Re: Repeat With + Property List + leaderboard / rank of best scores
                jackblackweb Level 1

                Hey MAC800,

                 

                Heres a way using text strings and comma separated values to sort scores and contestant names for display.

                 

                Link to sample movie:

                http://www.theclickpoint.com/DIRECTOR FORUM/sortScores.dir

                 

                Screen shot of display:

                scoreDisplay.PNG

                 

                Code:

                 

                on mouseDown me

                 

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

                  -- here a string of comma separated scores is created "scores"

                  scores = ""

                  firstScoreMemberNumber = member("score1").number

                  lastScoreMemberNumber = member("score50").number

                  repeat with scoreMemberNumber = firstScoreMemberNumber to lastScoreMemberNumber       

                    if member(scoreMemberNumber).text > "" then -- avoid error

                      scoreToAdd = string(member(scoreMemberNumber).text).value       

                      scores = scores&scoreToAdd&","   

                    end if   

                  end repeat

                  -- delete last comma to avoid error

                  if scores.char[scores.char.count] = "," then delete scores.char[scores.char.count] 

                  -- put scores

                  -- "22,59,67,62,77,84,98,22,73,99,79,62,84,69,61,77,64,84,89,99"

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

                 

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

                  -- here a string of comma separated contestant names is created "names"

                  names = ""

                  firstScoreMemberName = member("contestants1").number

                  lastScoreMemberName = member("contestants50").number 

                  repeat with scoreMemberName = firstScoreMemberName to lastScoreMemberName   

                    if member(scoreMemberName).text > "" then -- avoid error

                      nameToAdd = member(scoreMemberName).text

                      names = names&nameToAdd&","

                    end if

                  end repeat

                  -- delete last comma to avoid error

                  if names.char[names.char.count] = "," then delete names.char[names.char.count] 

                  -- put names

                  -- "Bob,John,Susie,Paul,Judie,Ray,Chris,Jose,Katie,Quen,Arnold,Betty,Mary,Marlo,Julio,Ben,Ke vin,Matthew,Barack,George"

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

                 

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

                  -- here the contestants name and score are placed on the line number of member("step1").text corresponding to the score value

                  -- for example, if the score is 20 the contestants name and score are placed on line 20 (separated by a colon &SPACE)

                  -- if contestant scores match they are placed on the same line separated by a comma

                  member("step1").text = ""

                  repeat with zxc = 1 to scores.item.count 

                    member("step1").line[string(scores.item[zxc]).value] = member("step1").line[string(scores.item[zxc]).value]&names.item[zxc]&":"&SPACE&scores.ite m[zxc]&","

                  end repeat 

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

                 

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

                  -- here a comma separated string of the contestants names and scores is created

                  step2 = ""

                  repeat with zxc = 1 to member("step1").line.count   

                    if member("step1").line[zxc] > "" then      

                      step2 = step2&member("step1").line[zxc]

                    end if       

                  end repeat

                  -- delete last comma to avoid error

                  if step2.char[step2.char.count] = "," then delete step2.char[step2.char.count] 

                  -- put step2

                  -- "Bob: 22,Jose: 22,John: 59,Julio: 61,Paul: 62,Betty: 62,Kevin: 64,Susie: 67,Marlo: 69,Katie: 73,Judie: 77,Ben: 77,Arnold: 79,Ray: 84,Mary: 84,Matthew: 84,Barack: 89,Chris: 98,Quen: 99,George: 99"

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

                 

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

                  -- here the contestants name and score are copied as items to member("displayScores").text 

                  member("displayScores").text = ""

                  repeat with zxc = 1 to step2.item.count

                    member("displayScores").text = member("displayScores").text&step2.item[zxc]&RETURN

                  end repeat 

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

                 

                end