我有一個JS函數,加載時調用一些變量,這一切運作良好,但是當我從另一個函數調用函數,我得到這個錯誤Cannot call method 'split' of undefined
:不能調用未定義的方法「拆分」 - 調用從函數
function loadInAttachmentsIntoSquads(){
// eg: 5000,5000,5000,5000 > [5000][5000][5000]
myAttachmentArray = currentAttachments.split(',');
//eg: [5000][5000][5000] > [5][0][0][0]
//myAttachmentForWeapon = myAttachmentArray[mySquadsIndex].split('');
setupWeaponAttachments();
}
function setupWeaponAttachments(){
myAttachmentForWeapon = myAttachmentArray[mySquadsIndex].split('');
//if(mySquadsIndex == 0){
if(myAttachmentForWeapon[1] == 1){ // if silencer is on? //first digit is always 5
weaponAttachments.silencer = true;
}
else{
weaponAttachments.silencer = false;
}
if(myAttachmentForWeapon[2] == 1){ // if silencer is on? //first digit is always 5
weaponAttachments.grip = true;
}
else{
weaponAttachments.grip = false;
}
if(myAttachmentForWeapon[3] == 1){ // if silencer is on? //first digit is always 5
weaponAttachments.redDot = true;
}
else{
weaponAttachments.redDot = false;
}
// -- applies visuals -- \\
applyWeaponAttachments();
}
如果我打電話setupWeaponAttachments()
從另一個函數,我得到這個錯誤...爲什麼?
'mySquadsIndex'的價值是什麼? –
它是一個動態值,範圍從0到4(有效) –
它並不完全工作,因爲它被設置爲數組中沒有任何內容的索引。 –