2017-04-15 8 views
1
client.on('chat', function(channel, userstate, message, self){ 



    switch(message){ 
    case message.includes(emotes[0]): 
     numberOfEmotes[0]++; 
     console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)"); 
     break; 
    case message.includes(emotes[1]): 
     numberOfEmotes[1]++; 
     console.log("Emote1 has been used " + numberOfEmotes[1] + " time(s)"); 
     break; 
    case message.includes(emotes[2]): 
     numberOfEmotes[2]++; 
     console.log("Emote2 has been used " + numberOfEmotes[2] + " time(s)"); 
     break; 
    case message.includes(emotes[3]): 
     numberOfEmotes[3]++; 
     console.log("Emote3 has been used " + numberOfEmotes[3] + " time(s)"); 
     break; 
    } 

/* if(message.includes(emotes[0])){ 
    numberOfEmotes[0]++; 
    console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)"); 
    }*/ 


    //console.log("** " + message + " **"); 
}); 

機能chat.onが呼び出されると、文字列を使用してメッセージの変数は、switchステートメントを介して実行することになっている場合、私は別の文字列の配列を持っており、メッセージには、その配列からの文字列が含まれています。しかし、何も起こらない、それはすべてここで間違っている可能性があるようだ?Switchステートメント()

+1

でそれを配置する必要があります 'より密接switch'。 –

答えて

1

期待通りのスイッチが動作しません。それはswitchで書かれた値を受け取り、caseブロックでそれぞれと比較します。したがって、あなたのケースでは、真偽値と値メッセージを比較し、同じ値を見つけられず、結果として何も起こりません。 あなたはのドキュメントを読む場合はelseステートメントを使用するか、メッセージを解析し、スラッシュAFTEすべてを抽出 メッセージ「タイプ/ emote1」のような値を除外し、スイッチ

+0

私は基本的に文字列 'message'をチェックし、文字列' mesage'に 'emote [0]'が含まれていればcase文を実行します。今私は4を持っていますが、私はそれが動作することを知った後私は46を追加します。 – Hooga

関連する問題