2014-05-19 66 views
0

下午好。在第一眼看,這個問題看起來已經回答了,儘管我不能用我找到的答案解決我的問題。Uncaught TypeError:無法讀取原型函數中未定義的屬性'值'

我有一個類,其中一個函數應該調用另一個函數(通過「自我」網格有參數),這就是問題,我失去了參考的地方,我找不到在哪裏。

下面的代碼,並提前:)

//classe unit. 
function unit(unitId, mesh, unitName, shieldSize, armor, armorTechLvl, shieldTechLvl, employeesNeeded, description, imageFilePath, structureNeeded, storageSize, unitSpeed, attackPower, weaponTech) { 
    var unitId; 
    var unitName; 
    var shieldSize; 
    var armor; 
    var armorTechLvl; 
    var shieldTechLvl; 
    var employeesNeeded; 
    var description; 
    var imageFilePath; 
    var structureNeeded; 
    var storageSize; 
    var unitSpeed; 
    var attackPower; 
    var weaponTech; 
    var shipposx; 
    var shipposz; 
    var mesh; 
    this.unitId = unitId; 
    this.unitName = unitName; 
    this.shieldSize = shieldSize; 
    this.armor = armor; 
    this.armorTechLvl = armorTechLvl; 
    this.shieldTechLvl = shieldTechLvl; 
    this.employeesNeeded = employeesNeeded; 
    this.description = description; 
    this.imageFilePath = imageFilePath; 
    this.structureNeeded = structureNeeded; 
    this.storageSize = storageSize; 
    this.unitSpeed = unitSpeed; 
    this.attackPower = attackPower; 
    this.weaponTech = weaponTech; 
    this.shipposx = 0; 
    this.shipposz = 0; 
    this.mesh = mesh; 


unit.prototype.setMesh = function (mesh){ 
    this.mesh = mesh; 
    this.mesh.position.x = unit.prototype.getShipPosx(); 
    this.mesh.position.z = unit.prototype.getShipPosz(); 
    this.mesh.position.y = 0; 
    this.mesh = this; 
}; 

unit.prototype.setShipPos = function (posx,posz){ 
    this.shipposx = posx; 
    this.shipposz = posz; 
    //self.position.x =posx; 
    //self.position.z =posz; 
    //self.position.y =0; 
    unit.prototype.setMesh(this.mesh); 
}; 

unit.prototype.getShipPosx = function(){ 
    return this.shipposx; 
}; 

unit.prototype.getShipPosz = function(){ 
    return this.shipposz; 
}; 


//método que define o tamanho do shield inicial. 
unit.prototype.setShieldSize = function(){ 

}; 
//método que altera o armor e shield mediante o damage até à destruição da unidade. 
unit.prototype.setDamage = function(damage) { 
    var armorCheck = false; 
    if (this.shieldSize > 0){ 
     this.shieldSize = this.shieldSize - damage; 
    } 
    else if (this.shieldSize < 0){ 
     this.shieldSize = 0; 
     armorCheck = true; 
    } 
    if (armorCheck === true){ 
     this.armor = this.armor - damage; 
    } 
    else if (this.armor < 0){ 
     this.armor = 0; 
     delete unit; 
     //não esquecer, se houver tempo implementar chamada à explosão da unidade ex: explode(). 
    } 
}; 
//possivel método de explosão. 
unit.prototype.explosion = function(posx,posy){ 
    //carrega uma explosão na posição x e posição y. 
}; 

//método para carregar objeto 3D da unidade. 
unit.prototype.load3D = function(name,imageFileName){ 
    BABYLON.SceneLoader.ImportMesh(name, "Assets/babylonreadyfiles/", imageFileName, scene, function(newMeshes) { 


    newMeshes[0].scaling.x = 0.2; 
    newMeshes[0].scaling.y = 0.2; 
    newMeshes[0].scaling.z = 0.2; 

    unit.prototype.setMesh(newMeshes[0]); 
    //if (selfchecker === 0) { 
    //selfchecker = 1; 
    /*$.get("Communications/getUnit.php", function(data) { 
     //console.log(data); 
     var name = jQuery.parseJSON(data); 

    });*/ 
    /*$.get("Communications/getPosition.php", function(data) { 
     //console.log(data); 
     var pos = jQuery.parseJSON(data); 
     newMeshes[0].position.x = pos.posx; 
     newMeshes[0].position.z = pos.posy; 
     newMeshes[0].position.y = 0; 
    });*/ 

    //}; 


    }); 

}感謝;

}

+0

..這是怎麼發生的?當然,你不能期望我們查看124行代碼,並希望找到未定義的函數? **編輯**:實際上您發佈的代碼從未引用'.value' *一次*。 – h2ooooooo

+0

當然。抱歉,是我的錯。當我調用「unit.prototype.setMesh(this.mesh);」在unit.prototype.setShipPos函數中。 – Saguim

回答

相關問題