-1

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)
    }
}
Kong
  • 35
  • 1
  • 7

2 Answers2

0

Something like this may work for you. You are using variables that are undefined. It also looks as though you are not paying attention to the cases of the variables that you are defining.

var viewersWTP = [];   // add this or define it elsewhere
function lfg(user){
    var 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)
    }
}
Jon
  • 2,456
  • 21
  • 28
0

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

Kong
  • 35
  • 1
  • 7