我有一个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(有效) –
它并不完全工作,因为它被设置为数组中没有任何内容的索引。 –