7 Replies Latest reply on Apr 29, 2008 3:25 PM by skn154

    scores

    skn154
      Hello everyone,

      I'm creating a dressup game for kids, which will have a score system. There are 3 items of clothing worth 10, 15 and 20 points. On one page they can select the garments. I've created a global variable called gScore and have set it to 0 in startmovie.

      On the sprite of each garment of clothing I've used the following code

      gscore = gscore + 20

      Thing is, each time you click, it adds 20 to the total. so if you click twice, the total will be 40. I only want it to add to the total once and not each time a user clicks.

      If the user click on another garment of clothing; for example worth 15 points, that will be add to 40. I also don't want this to happen as the user can only select one garment of clothing. So basically the user can score a maximum of 20 points, because they can only select 1 item of clothing.

      If I select the garment worth 15 points, and change my mind and select the garment worth 20 points, how can I recognise this and deduct 15 point from the total and add 20?

      Its sounds confusing but hope you can help... Thanks everyone
        • 1. Re: scores
          Level 7
          Instead of (or in addition to) your gScore global, I would make another
          global for each clothing type. I have no idea how your game is
          structured, but let's say you have Shirts, Pants, and Shoes. Each time
          you click on a shirt, it will put in that shirt's value and remove the
          previously saved shirt value while leaving the rest intact.


          global gScore
          on startMovie
          gScore=[:]
          gScore[#shirts]=0
          gScore[#pants]=0
          gScore[#shoes]=0
          end

          That will instantiate your list when the movie starts. Then you would
          put this on each clickable clothing item:

          global gScore
          property pGarmentType
          property pValue

          on mouseUp me
          gScore[symbol(pGarmentType)]=pValue
          end

          on getPropertyDescriptionList me
          p=[:]
          p[#pGarmentType]=[#format:#string,#comment:"Which garment
          type?",#default:"shirts",#range:["shirts","pants","shoes"]]
          p[#pValue]=[#format:#integer,#comment:"How much is this one
          worth?",#default:0]
          return p
          end

          (watch out for inadvertent line breaks - that should be exactly 14 lines
          of code) That will let you define which garment type the item is, and
          how much it is worth. Feel free to set the different garment types to
          be appropriate for your use...

          Anyway, on your score counter, you would simply add the values together
          like this:

          global gScore
          on enterFrame me
          theScore=gScore[#shirts]+gScore[#pants]+gScore[#shoes]
          sprite(me.spriteNum).member.text=string(theScore)
          end
          • 2. scores
            skn154 Level 1
            Thanks Mike,

            I'm having trouble understanding the code that goes into the clickable item of clothing. I am also getting an error message gScore[symbol(pGarmentType)]=pValue - Index out of range

            There are three outfits to chose from. I've named them : Outfit1, Outfit2, Outfit3
            Outfit1 = 10 points
            Outfit2 = 15 points
            Outfit3 = 20 points

            how does the following code work?

            p[#pGarmentType]=[#format:#string,#comment:"Which garment type?",#default:"shirts",#range:["shirts","pants","shoes"]]
            p[#pValue]=[#format:#integer,#comment:"How much is this one worth?",#default:0]

            I'm not familiar with properties

            Thanks so much for your help, hopefully I'll learn something new! I'll be using the same score technique further on in the application, where the user can design the outfit type they've chosen (from the 3 outfit types above - outfit 1, 2 or 3) from a selection of graphics that will be available to them. If they get enough points they'll unlock other designs and outfits.

            Many Thanks
            • 3. Re: scores
              Level 7
              That stuff is part of the "getPropertyDescriptionList" handler.
              Basically, when you put the script onto a sprite, it will present you
              with a few options. And the options you choose in that menu will define
              how the script works. In this case, there are 2 questions it will ask.
              One is garment type and the other is value.

              You will get the value out of range if you are trying to set the score
              of a garment type that does not exist.

              In startMovie, we set three different garment types, Shirts, Pants, and
              Shoes. Each clickable clothing item will be one of those three types.
              Which one it is will be defined by your selection in the GPDL.

              If it is easier to understand without using properties, the point of the
              situation is that we have 3 globals defining the score. Not just the
              one gScore. I separated them and put them into a single property list.
              You could use 3 globals like gShirtScore, gPantsScore, gShoesScore.
              Then each time you click a Show item, it sets the value of gShoeScore.
              And the text sprite that shows the actual score simply adds the three
              together.
              • 4. Re: scores
                skn154 Level 1
                Hi there,

                Still having problems with the scores. I'm not that advanced in coding and didn't quite understand how it can be done. I've explained the problem above and I'm sure theres a much better way of doing it. I've done it in the following way

                I've added this script to the garments

                global gGarmentScore

                gsGarmentScore=string(20)

                member("score").text= gGarmentScore

                and then added this to the graphics that goes onto the garment

                --add graphic points

                global gscoreGraphics, gScore, gtotal

                gscoreGraphics=string(50)

                member("score2").text=gscoreGraphics


                --show total

                gtotal = (gScore) + (gscoreGraphics)

                member("total").text= string(gtotal)


                I want to be able to add the chosen outfit points to the chosen graphics, so if they've scored enough the next level can be unlocked.
                the total appears in the total field, but it comes up as a decimal. Is there a way I can get rid of the decimal.

                Thanks for your help
                • 5. Re: scores
                  UdoGre Level 1
                  Hi skn,

                  You're mixing up numbers and strings. Try it this way:

                  global gGarmentScore

                  gGarmentScore=20
                  member("score").text= string(gGarmentScore)

                  --add graphic points
                  global gscoreGraphics, gScore, gtotal

                  gscoreGraphics=50
                  member("score2").text=string(gscoreGraphics)

                  --show total
                  gtotal = gScore + gscoreGraphics

                  member("total").text= string(gtotal)

                  HTH,

                  Udo
                  • 6. Re: scores
                    Level 7
                    Change the line that puts the score into the text member to this:

                    member("total").text= string(integer(gtotal))

                    Basically, it takes gTotal and turns it into an integer (drops anything
                    after the decimal). Then it turns it into a string so you can put it
                    into the text box.
                    • 7. scores
                      skn154 Level 1
                      Thanks Mike! problem sorted! :D