2 Replies Latest reply on Aug 4, 2008 4:56 AM by Newsgroup_User

    problems with testing varialbes

    Mongolish
      ok, so i have a simple shooter type game set up. i have crosshairs that move with the mouse (which works).
      then i have my boxes names target, and target1. i am trying to make it so that when both of these are clicked you move on. targetstat, and target1stat are my variables that i made to test if they have been clicked on yet. i am basically new to this :/
        • 1. Re: problems with testing varialbes
          Level 7
          target.onPress = function() {
          target.gotoAndStop("dead");
          targetstat = true;
          }
          target1.onPress = function () {
          target1.gotoAndStop("dead");
          target1stat = true;
          }
          if (_root.targetstat == true) {
          if (.target1stat == true) {
          play();
          }
          }


          Couple of things here. First, you should _always_ declare variables before
          using them. Your targetstat, and target1stat variables are not doing what
          you want because you did not declare them, and they are now local to their
          onPress functions only. The rest of your code can not see them. Also, since
          the code is not in a loop, your test at the end is only ever executed once.
          Something like this should be more what you had in mind:

          var targetstat = false;
          var target1stat = false;

          target.onPress = function() {
          target.gotoAndStop("dead");
          targetstat = true;
          if(targetstat && target1stat){
          //both targets hit do stuff
          }
          }
          target1.onPress = function () {
          target1.gotoAndStop("dead");
          target1stat = true;
          if(targetstat && target1stat){
          //both targets hit do stuff
          }
          }


          --
          Dave -
          www.offroadfire.com
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: problems with testing varialbes
            Level 7
            One more quick thing:


            target1.onPress = function () {
            target1.gotoAndStop("dead");

            Inside of a function like this, you can use 'this' because the code is
            executing on the timeline of target1:


            target1.onPress = function () {
            this.gotoAndStop("dead");


            --
            Dave -
            www.offroadfire.com
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/