1 Reply Latest reply on Mar 31, 2013 11:13 AM by Eversir2

    Checking for an updated variable value in symbol timeline

    Eversir2

      I'm making a puzzle which involves moving crates in a specific order to get a character from one side to the other. Take a look at http://tinyurl.com/c4vwcj9 to get the gist of it.

       

      Each crate is a symbol with it's own timeline. A crate may only move a pre-determined direction and distance once clicked. No more than 2 crates can be pulled out of the grid at any one time.

       

      The timeline of each symbol has three states: "Original", "Moved" and "Returned".

       

      If you have a play around with the puzzle as it stands so far, you will see most of the logic arguments work ok. However, the problem I have is when you pull a crate out of the grid and it needs to check if it can move back into place.

       

      To see what I mean:

       

      - Pull out the bottom left corner crate

      - Move the crate to the immediate right, thereby blocking the previous crate

      - Try to move the bottom left corner crate again (you should get an error message and it shouldn't move - this is fine)

      - Move the other crate back to it's original position to unblock the previous crate

      - Try to move the bottom left corner crate a final time (you still get the error message and it doesn't move - this is not fine!)

       

      A quick debug has revealed the second mouse click doesn't fetch the updated variable AFTER the symbol timeline begins to play, but the same methodology works just fine for crates that check for impeded movement BEFORE a symbol timeline is played (try one of the inner crates). Why isn't it getting the updated value and what can I do to solve it?

       

      Below is a sample of the code specific to the bottom left crate. I've highlighted the variable and arguments specific to the problem. Please excuse what is no doubt poor Javascript coding conventions - I only started learning this last week!

       

       

       

       

       

      //-- Get needed variables

       

      // Check to see if other crate is impeding movement and define value as a variable

      var myCrateCheck = sym.getComposition().getStage().getSymbol("_b_2x1crate_h").getVariable("Crate2");

       

      // Check to see what this crate's status is and define value as a variable

      var mySelfCheck = sym.getComposition().getStage().getSymbol("_bl_3x1crate_h").getVariable("Crate1");

       

      // Check to see if other crates have been moved out of the main grid. Parse value as an integer in base 10.

      var myGridCheck1 = parseInt(sym.getComposition().getStage().getSymbol("_br_2x1crate_v").getVariable("Crate3_ grid"),10);

      var myGridCheck2 = parseInt(sym.getComposition().getStage().getSymbol("_bl_4x1crate").getVariable("Crate4_gr id"),10);

      var myGridCheck3 = parseInt(sym.getComposition().getStage().getSymbol("_bl_2x2crate").getVariable("Crate5_gr id"),10);

      var myGridCheck4 = parseInt(sym.getComposition().getStage().getSymbol("_cl_2x1crate_h").getVariable("Crate9_ grid"),10);

      var myGridCheck5 = parseInt(sym.getComposition().getStage().getSymbol("_cl_1x1crate_1").getVariable("Crate13 _grid"),10);

      var myGridCheck6 = parseInt(sym.getComposition().getStage().getSymbol("_cr_3x1crate_h").getVariable("Crate16 _grid"),10);

      var myGridCheck7 = parseInt(sym.getComposition().getStage().getSymbol("_tl_2x1crate_h").getVariable("Crate17 _grid"),10);

      var myGridCheck8 = parseInt(sym.getComposition().getStage().getSymbol("_tc_2x2crate").getVariable("Crate18_g rid"),10);

      var myGridCheck9 = parseInt(sym.getComposition().getStage().getSymbol("_tr_2x1crate_h_1").getVariable("Crate 19_grid"),10);

      var myGridCheck10 = parseInt(sym.getComposition().getStage().getSymbol("_tl_3x1crate_h").getVariable("Crate20 _grid"),10);

      var myGridCheck11 = parseInt(sym.getComposition().getStage().getSymbol("_tr_2x1crate_h_2").getVariable("Crate 21_grid"),10);

      // Create a variable called myGridCheckSum, make sure it's a number and sum the above

      var myGridCheckSum = 0;

      myGridCheckSum = myGridCheck1 + myGridCheck2 + myGridCheck3 + myGridCheck4 + myGridCheck5 + myGridCheck6 + myGridCheck7 + myGridCheck8 + myGridCheck9 + myGridCheck10 + myGridCheck11;

       

      //-- Logic & Conditional Statements

       

      // If this crate is in any position other than "Moved", and more than 1 box is already out of grid zone - prevent move and alert

      if ((mySelfCheck != "Moved") && (myGridCheckSum >1)){

      alert('Too many boxes outside of grid zone');

      sym.stop();

      }

      // Or else, if this crate is in any position other than "Moved", but less than 2 boxes are out of grid zone - allow move

      else if ((mySelfCheck != "Moved") && (myGridCheckSum <2)){

      sym.play();

      }

      // If this crate has moved but the other crate hasn't moved, play remainder of symbol timeline

      else if ((mySelfCheck == "Moved") && (myCrateCheck != "Moved")){

      sym.play(3001)

      }

      // If this crate has moved and the other crate is also moved, alert and loop back on timeline

      else if (myCrateCheck == "Moved"){

      // Alert user to say crate cannot be moved

      alert('This box is being blocked by another!');

      sym.play(2999);

      }