Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear ent: variables after a certain amount of time as expired

Tags:

krl

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!!

like image 926
jon Avatar asked Dec 29 '25 03:12

jon


1 Answers

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().

like image 168
TelegramSam Avatar answered Dec 31 '25 00:12

TelegramSam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!