Error Code On Number Jump Game

Discussion in 'Technical Discussion' started by JDMorrison, Mar 21, 2020.

  1. JDMorrison

    JDMorrison Boxer

    Joined:
    Mar 16, 2020
    Messages:
    5
    Likes Received:
    0
    I have been playing around with this Number jump Game zack did a video about. Every time I run the game I start getting errors. Even though the game seems to work as it should. I have looked at the touch move ph node and can't find the problem. I have even used a new touch move node and wrote the code from the touch move ph. A deleted the touch move ph and it still gave me error pointing me to the touch move ph node that was deleted. Which is kinda weird I will paste the move Ph code and attach a pic of the error. Any advice would be great!
    there is no line 0

    Error JS Error [asset: MainCharacter , component: Touch Move Ph, line: 0] - TypeError: _target is undefined

    Toch Move ph code


    var _speed;
    var _enabled = false;
    var _prev;
    var _target;
    var _phys;

    //----Standart
    function init(){
    this.enableTouch();
    _speed = this.attribute('Speed');

    _phys = this.entity().physics();
    }
    function update( dt ){
    let x = this.entity().position().x;
    let delta = x - _target.x*0.02;

    let vel = _phys.linearVelocity();
    vel.x = -delta*20;
    _phys.setLinearVelocity(vel.x, vel.y, vel.z);
    }
    function signal( name, value){
    _enabled = value;
    }
    //----Move
    function move( point ){
    if(_enabled){
    let wp = this.scene().screenToWorld(point.x, point.y);

    _target = new Vec3((point.x-320)*_speed.x,
    0,
    0);

    }
    }
    component.move = move;

    //----Touches
    function touchBegan( point ){
    this.move( point );

    _prev = point;
    }
    component.touchBegan = touchBegan;

    function touchMove( point){
    this.move( point );
    _prev = point;
    }
    component.touchMove = touchMove;

    function touchEnded(){
    }
    component.touchEnded = touchEnded;
     

    Attached Files:

  2. JDMorrison

    JDMorrison Boxer

    Joined:
    Mar 16, 2020
    Messages:
    5
    Likes Received:
    0
    Nevermind I figured the problem out
     
  3. Sayonara

    Sayonara Boxer

    Joined:
    Apr 2, 2020
    Messages:
    1
    Likes Received:
    0
    could you explain what the solution was?
     

Share This Page