Search code examples
javascriptnode.jstwitch

Variable not accessing inside of function


ive made a function for my twitch bot. which when they input a command checks if they are already in the list. if they are not in the list it will add them to the list. The code below outputs this : [ undefined ] [17:53] info: [#kong_plays] *<kng_bot>: 1

var wtpLength = [];
function lfg(user){
    WTPLength = viewersWTP.length;
    if (WTPLength !== 0) {
        viewersWTP = viewersWTP - 1
        while(WTPLength !== -1){
            if(user === viewersWTP[WTPLength]){
                console.log("Already in list")
                client.action("kong_plays",user+" you cannot execute this command again until kong pulls a viewer to play with him!")
            }else{
            viewersWTP.push(user['display-name'])
            console.log("Added into list")
            client.action("kong_plays",viewersWTP)
            }
        }
    }else{
        viewersWTP.push(user['display-name'])
            console.log(viewersWTP)
            client.action("kong_plays","1"+viewersWTP)
    }
}

Solution

  • Change the user['display-name'] into user. You passed that var throught the function