views:

63

answers:

5
function FM_log(level, text) {

    // caso não seja log total escolhe o que loga
    var log = false;
    switch (level) {
        case "addtoprio()":log = true;
        case "alternaTropas()":log = false;
        case "sendtroops()":log = false;
        defalt: log = false;
    }

    if ((logTotal == false) && (log == true))
        GM_log(horaAtual() + " - "+level+", "+text);
    else if (logTotal == true)
        GM_log(horaAtual() + " - "+level+", "+text);    
}

how to do that switch is a way it works?

+2  A: 

You must add break instruction after each case, and use default not defalt.

Aif
+4  A: 

Two Problems:

  • You are missing the break keyword after each case clause.
  • Your spelling for the default was wrong.

.

   switch (level) {
        case "addtoprio()":log = true; break;
        case "alternaTropas()":log = false; break;
        case "sendtroops()":log = false; break;
        default: log = false; break;
    }

More On Switch

Sarfraz
same here: default not defalt.
Aif
@Aif: Yup, his spelling was not right.
Sarfraz
+2  A: 

Change it to this:

function FM_log(level, text) {

    // caso não seja log total escolhe o que loga
    var log = false;
    switch (level) {
        case "addtoprio()":log = true; break;
        case "alternaTropas()":log = false; break;
        case "sendtroops()":log = false; break;
        defalt: log = false; break;
    }

    if ((logTotal == false) && (log == true))
        GM_log(horaAtual() + " - "+level+", "+text);
    else if (logTotal == true)
        GM_log(horaAtual() + " - "+level+", "+text);    
}
orokusaki
+6  A: 

break statements for your switch, and proper spelling of "default" should help you on your way :)

function FM_log(level, text) 
{
   // caso não seja log total escolhe o que loga
   var log = false;
   switch (level) 
   {
      case "addtoprio()":
         log = true;
         break;
      case "alternaTropas()":
         log = false;
         break;
      case "sendtroops()":
         log = false;
         break;
      default: 
         log = false;
         break;
   }

   if ((logTotal == false) && (log == true))
      GM_log(horaAtual() + " - "+level+", "+text);
   else if (logTotal == true)
      GM_log(horaAtual() + " - "+level+", "+text);    
}
KevenK
A: 

easy. thanks everyone

Fernando SBS