9 Replies Latest reply on Jun 23, 2011 7:15 AM by kglad

    setting up a stats system for a game (as3)

    everebo

      Hello,

       

      I am making up a small flash game for my own amusement, and need some help getting started.  its a simple stats based rpg type game but i'm struggling to set things up so that when you click certain buttons your stats score in one parameter will go up and another may go down.

       

      i've attached a mock up screen shot as I think that may make more sense...

      flashhelpgame.jpg

       

      so the idea is there's 20 stats in the 'points remaining' to start with and then by pressing the relevant forwards and back buttons the stats in relevant areas would go up/down 1 point until all the 'point remaining' have been allocated an error message would appear saying "all your points have been allocated press 'next' to continue" or something like that.  and these scores would be stored so that they can be further adjusted on the next screen (screens are all set up on one timeline with labels distinguishing them.).

       

      I started messing around with something along these lines after a google search for help,  but i'm very new at all this so wasn't getting anywhere :/

       

      var score:uint;

      function init():void

       


      score = 0; 
      scorecounterSTR.text = score.toString(); 
      CLIP.buttonMode = true; 
      CLIP.addEventListener(MouseEvent.CLICK, on_press); 
      }


      function on_press(event:MouseEvent):void 

      updateScore(); 

      function updateScore():void 

      score += 2;

      scorecounterSTR.text = score.toString(); 

      init();

       

      couldn't decide where to put the IF statements, and just generally got myself lost.

       

      any help at all would be greatly appreciated.

       

      Thank you

        • 1. Re: setting up a stats system for a game (as3)
          kglad Adobe Community Professional & MVP

          what's wrong with your code?


          • 2. Re: setting up a stats system for a game (as3)
            everebo Level 1

            Well at the moment nothing happens and it comes up with this error message....

             

            1119: Access of possibly undefined property buttonMode through a reference with static type flash.display:SimpleButton.

             

            (i've used a premade library button for now)

             

            I havent put the other parts of the code in so that it will stop the user after 20 points have been allocated and ideally display the remaining points though.

            • 3. Re: setting up a stats system for a game (as3)
              kglad Adobe Community Professional & MVP

              remove that line of code.   flash is telling you there is no such property of a button.

               

              button's, by default, act like buttons so it doesn't make sense to assign a buttonMode property to a button.

              1 person found this helpful
              • 4. Re: setting up a stats system for a game (as3)
                everebo Level 1

                thanks, so that worked and now when I click one of the buttons the score goes up as I wanted.

                 

                I've been trying to adjust the code so that it also works to put the score down as well without much luck.

                 

                at the moment i've got this which is putting the numbers up...

                 

                var scoreSTR:uint;

                function init():void


                scoreSTR = 0; 
                scorecounterSTR.text = scoreSTR.toString(); 

                STR_PLUS.addEventListener(MouseEvent.CLICK, on_press); 

                function on_press(event:MouseEvent):void 

                updateScoreUP(); 

                function updateScoreUP():void 

                scoreSTR += 2;

                scorecounterSTR.text = scoreSTR.toString(); 

                init();

                I figure something like this should be added so the numbers can be put down when a different button (STR_DOWN) is pressed

                 

                STR_DOWN.addEventListener(MouseEvent.CLICK, on_press); 

                function on_press(event:MouseEvent):void 

                updateScoreDOWN(); 

                function updateScoreDOWN():void 

                scoreSTR -=2;

                scorecounterSTR.text = scoreSTR.toString(); 

                I cant quite firgure out how to add it into the code, everything I have tried produces an error message :/

                • 5. Re: setting up a stats system for a game (as3)
                  kglad Adobe Community Professional & MVP

                  what error message from using the code you showed?

                   

                  p.s.  please mark helpful/correct answers, if there are any.

                  • 6. Re: setting up a stats system for a game (as3)
                    everebo Level 1

                    so this is the code I have.

                     

                    the top half should make the stats go up by 2 when a button is clicked and the bottom half make it go down by 2 when a different button is clicked.

                    but an error message is produced saying "1087: Syntax error: extra characters found after end of program."  I cant figure out what needs removed/altered.

                     

                    var scoreSTR:uint;

                    function init():void


                    scoreSTR = 0; 
                    scorecounterSTR.text = scoreSTR.toString(); 

                    STR_PLUS.addEventListener(MouseEvent.CLICK, on_press); 

                    function on_press(event:MouseEvent):void 

                    updateScore(); 

                    function updateScore():void 

                    scoreSTR += 2;

                    scorecounterSTR.text = scoreSTR.toString(); 

                    init();


                    var scoreSTR:uint;

                    function init():void

                    }

                    STR_DOWN.addEventListener(MouseEvent.CLICK, on_press); 

                    function on_press(event:MouseEvent):void 

                    updateScoreDOWN(); 

                    function updateScoreDOWN():void 

                    scoreSTR -=2;

                    scorecounterSTR.text = scoreSTR.toString(); 

                    init();

                     

                    thanks for the help

                    • 7. Re: setting up a stats system for a game (as3)
                      kglad Adobe Community Professional & MVP

                      your first error is:

                       


                       

                      var scoreSTR:uint;

                      function init():void


                      scoreSTR = 0; 
                      scorecounterSTR.text = scoreSTR.toString(); 

                      STR_PLUS.addEventListener(MouseEvent.CLICK, on_press); 

                      function on_press(event:MouseEvent):void 

                      updateScore(); 

                      function updateScore():void 

                      scoreSTR += 2;

                      scorecounterSTR.text = scoreSTR.toString(); 

                      init();


                      var scoreSTR:uint;

                      function init():void

                      }  // <-- that should be {

                      STR_DOWN.addEventListener(MouseEvent.CLICK, on_press); 

                      function on_press(event:MouseEvent):void 

                      updateScoreDOWN(); 

                      function updateScoreDOWN():void 

                      scoreSTR -=2;

                      scorecounterSTR.text = scoreSTR.toString(); 

                      init();

                       

                       

                      • 8. Re: setting up a stats system for a game (as3)
                        everebo Level 1

                        doh!

                         

                        thanks very much

                        that brought up one or 2 other wee things but I managed to sort them out no problem.

                        I have some follow up questions but i'll see if I can figure them out myself and if need help then i'll make another post

                         

                        thanks again

                        • 9. Re: setting up a stats system for a game (as3)
                          kglad Adobe Community Professional & MVP

                          you're welcome.