Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6838661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:37:25+00:00 2026-05-26T23:37:25+00:00

I have a JS function that is called on load that spilts some variables,

  • 0

I have a JS function that is called on load that spilts some variables, this all works well, but when I call the function from another function, I get this error 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();
}

If I call setupWeaponAttachments() from another function, I get that error … why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:37:26+00:00Added an answer on May 26, 2026 at 11:37 pm

    In the following:

    > function loadInAttachmentsIntoSquads(){
    >     
    >     myAttachmentArray = currentAttachments.split(',');
    > 
    >     setupWeaponAttachments(); 
    > }
    

    The identifier currentAttachments is used as if it’s a global variable. If it hasn’t been assigned value, or its value isn’t a string, at the time that the function is called, then an error will result.

    So the fix is to make sure it has a string value:

    function loadInAttachmentsIntoSquads(){
        if (typeof currentAttachments != 'string') return;
        ...
    }
    

    or deal with the error some other way.

    Also, where you are doing all those if..else blocks, consider:

    weaponAttachments.silencer = myAttachmentForWeapon[1] == 1;
    weaponAttachments.grip     = myAttachmentForWeapon[2] == 1;
    weaponAttachments.redDot   = myAttachmentForWeapon[3] == 1;
    

    It won’t be any faster, but it is a lot less code to write and read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java script function that i have called on body load mousemove()
I have a function that is being called from different threads in the application.
I have a Javascript function that is called from the onchange method in a
I have this function called ProperCase that takes a string, then converts the first
I have a function that gets called from an onclick event for example <a
I have a function that's called hundreds of thousands of times per update, and
I have a function that I use called sqlf(), it emulates prepared statements. For
I have an old function that is called many times in my application. I
I have a function that is often called inside of other functions, and I'd
I have an MS SQL function that is called with the following syntax: SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.