Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Aries

Hi, I'm following the tutorial from http://www.appmobi.com/index.php?q=node/171, but I'm getting Javascript error "Undefined variable left" when i try to access variable "left" at my entities player.js.

Currently I'm declare the variables at start of the <script> tag. Is it correct?

1 decade ago by TylerAppmobi

If you're using directCanvas you'll have to pass those variables down to the DC layer.

Here's an example of a function that should work:

function onSuccess(acceleration) 
         {   
         if(acceleration.x>0){
               if(Math.abs(acceleration.x)<0.99&&acceleration.y>0){right=acceleration.x;left=0;}
               else if(acceleration.x>-0.99&&acceleration.y<0){left=Math.abs(acceleration.x);right=0;}
               else{right=0;left=0;}
               dcPush(right,left)
            }
         else{
               if(Math.abs(acceleration.x)<0.99&&acceleration.y>0){left=acceleration.x;right=0;}
               else if(acceleration.x>-0.99&&acceleration.y<0){right=Math.abs(acceleration.x);left=0;}
               else{right=0;left=0;}
               dcPush(right,left)
            }
         
         };

   var options = { frequency: 500, adjustForRotation: false  };  // Update every half second
   var watchID = AppMobi.accelerometer.watchAcceleration(onSuccess, options);
  
   function dcPush(r,l){
      AppMobi.canvas.execute('right ='+r);
      AppMobi.canvas.execute('left ='+l);

   }

Then add
var left=0;
var right=0; 

Above line 1 in main.js to make them global variables on the DC side.

Let me know if that works for you .

1 decade ago by Aries

Hi, Tyler.

Thanks..it's works perfectly.
Page 1 of 1
« first « previous next › last »