Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
sendMessage executing twice even after if condition is fulfilled

I have a problem with the "cari" function, the data is correct but there is a

        txt = 'Material '+pola[1]+' tidak ditemukan atau perintah command tidak sesuai';
        sendMessage(cid,txt);
still appeared which is, it's no need to appear when the data is correct.
enter image description here enter image description here

function cari(cid,cmd){
  var txt = '';
  var pola = cmd.match(/cari#(.+)/);
  if (pola[1]!=''){
    var rs = bacadata();
    for (var i=0;i<rs.length;i++) {
      if (rs[i][0] == pola[1]){
        txt = 'Material '+pola[1]+' adalah '+rs[i][1];
        sendMessage(cid,txt);
      }
    }
    txt = 'Material '+pola[1]+' tidak ditemukan atau perintah command tidak sesuai';
    sendMessage(cid,txt);
  }
}

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try sendMessage() once after the loop:

function cari(cid,cmd){
  var pola = cmd.match(/cari#(.+)/);
  var txt = 'Data '+pola[1]+' tidak ditemukan atau perintah command tidak sesuai...';
  if (pola[1]!=''){
    var rs = bacadata();
    for (var i=0;i<rs.length;i++) {
      if (rs[i][0] == pola[1]){
        txt = pola[1]+' adalah '+rs[i][1];
        break;
      } 
    } //end of loop 
    sendMessage(cid,txt);          
  }
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!