3

I’m trying to clear certain ent: variables when a user first loads up their browser. I started with this example:

select using ".*" setting ()

if ent:browserOpened == 0 within 4 hours then {
    notify("Hello!", "Welcome to your browser! Kynetx rules doesn't it?)..... 
}
fired {
    ent:browserOpened += 1 from 1;
} else {
    ent:browserOpened += 1;
}

My version:

rule newWindow is active
  {
     //This rule checks to see if a persistent variable has been incremented in the 20 seconds
     select using ".*" setting ()

    if ent:browserOpened == 0 within 20 seconds then 
                 {                                                   
        popup(250, 250, 150, 400, "http://www.google.com")
       //noop();
           }
  fired 
         {
         ent:browserOpened += 1 from 1;  
         clear ent:clickMerchantID;                          
         }
    else 
         {    
         ent:browserOpened += 1;
         }                                  

  }

I suspect it has to do with how I am incrementing the ent:browserOpened variable. The popup only fires if I clear my cookies and refresh the browser. I guess it could also be the 'within' verb. Couldn't find much about it in the docs.

I’ll remove the popup and leave the noop() when I know the rule is firing properly.

Thanks for your help!!

jon
  • 31
  • 1

1 Answers1

3

You may have discovered a bug with the within clause and counters. In addition to keeping track of a counter, you can also use a flag. I tested the following and found it to work:

rule newWindow {
   //This rule checks to see if a persistent variable has been incremented in the 20 seconds
   select using ".*" setting ()

  if not ent:browserOpened within 20 seconds then 
               {                                                   
      notify("test", "condition passed!");
     //noop();
         }
fired 
       {
       set ent:browserOpened;  
       clear ent:clickMerchantID;                          
       }
  else 
       {    
       set ent:browserOpened;
       }                                  

}

Notes:

The within clause on a persistant variable (and usage of a flag) is shown in the docs here

Consider using notify() instead of popup() for testing, as it is more easily recognized and is nicer to observe then alert().

TelegramSam
  • 2,770
  • 1
  • 17
  • 22