5 Replies Latest reply on Apr 1, 2007 4:51 PM by Lukewig

    counting recognition

    sarahbarber Level 1
      I am a director novice - an uni tutors are not being too helpful PLEASE someone advise me on how to go about this problem:
      I am creating a counting game where you must find *4 of the same objects in a picture e.g 4 sharks, does anyone know the code for recognising when the 4 correct objects have been hit, so that the next button in sequence can start e.g 5 rabbits (its a 1-10 excercise and must go in order to continue game) Does this make any sense?
      *numbers vary.

      e.g on click count +1 upto max 7 once 7 items have been clicked next button active (obviously not the lingo but basic idea)

        • 1. Re: counting recognition
          Level 7
          I would do this by making a list of each of the sprite numbers for any
          given member. For instance sharks = [2,3,4,5] rabbits = [6,7,8,9,10].
          And then when the user clicks on any of those sprites, remove that
          sprite number from the list. When the list is empty, they have all of
          the items.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. counting recognition
            Chunick Level 3
            are the pictures with the animals single images or are they going to be comprised of several images placed over each other?... if it's a single image then you may be interested in this link:
            http://tinyurl.com/2lzw7k
            • 3. Re: counting recognition
              sarahbarber Level 1
              They are single images, e.g imagine like a wheres wally type layout which is comprised of lots of different object - in this case animals, for the first section you must find 3 different sharks and when you click on 3 of them you can then continue to the next chapter e.g find 4 stripy fish....and so on....
              • 4. Re: counting recognition
                sarahbarber Level 1
                Cheers for that but....

                Where should I create the instance of these sharks and rabbits is it on the image or should I create a new variable?
                do I use mouse event handler to remove the sprite number from the list?
                • 5. Re: counting recognition
                  Lukewig Level 1
                  Hi,

                  Assuming each of your 'clickable' objects are sprites (eg you have a graphic for a single shark which you have dragged on to the stage), then you could add a behaviour like this to each of these clickable sprites:

                  property myType

                  on CollectObjects(me, aList, id)
                  if (myType = id) then
                  if not (aList.getOne(me))then
                  -- if this object not in the list, then join
                  end if
                  end if
                  end

                  on getPropertyDescriptionList me
                  pdlist = [:]
                  -- set an id for this sprite
                  alist = [#type:#symbol, \
                  #comment: "What kind of thing is this", \
                  #default: #shark,\
                  #range: [#shark, #tuna]] -- add ids for the other objects here
                  -- add to the pdlist
                  pdlist[#myType] = alist

                  return pdlist
                  end

                  on mouseDown (me)
                  -- tell everyone that this object has been clicked!
                  sendAllSprites(#ObjectHasBeenclicked, me, myType)
                  end


                  Note - in the getPropertyDescriptionList method is a list with [#shark, #tuna]. Add all your other object types here. Each time you drag this behaviour on to a sprite, select the object type in the dialog that pops up (the 'getPropertyDescriptionList dialog').

                  Next step is to add the following behaviour to the frame script channel. This behaviour controls the game logic. Hopefully the comments will explain how it works:

                  property AllObjectTypes
                  property CurrentObjectType
                  property CurrentObjects

                  on exitFrame me
                  -- loop in the current frame
                  go to the frame
                  end

                  on beginSprite (me)

                  AllObjectTypes = [#shark, #tuna]-- add ids for the other objects here
                  CurrentObjects = []
                  me.StartNextRound()

                  end

                  on StartNextRound
                  if count(AllObjectTypes) > 0 then
                  -- determine the type of object for this round
                  CurrentObjectType = AllObjectTypes[1]

                  -- remove the selected type from the list
                  AllObjectTypes.deleteAt(1)

                  -- now collect a list of all these objects
                  CurrentObjects = []
                  sendAllSprites(#CollectObjects, CurrentObjects, CurrentObjectType)

                  else

                  alert ("Game Over!")

                  end if
                  end

                  on ObjectHasBeenclicked (me, obj, objtype)
                  -- has the object that has been clicked the right type?
                  if CurrentObjectType = objtype then
                  -- if so, is it in our list
                  if CurrentObjects.getOne(obj) then
                  -- delete it from the list
                  CurrentObjects.deleteOne(obj)
                  -- check that we have deleted all the objects
                  if count(CurrentObjects) =0 then
                  alert("Finished round")
                  me.StartNextRound()
                  end if
                  end if
                  end if
                  end