In KRL, is it possible to save a constant variable, not up?

I want the application variable to decrease, not up. I put the following in the entry of one rule:

fired { app:pies -= 1 from 10; } 

The app:pies variable will count from 10 to 1, but it never reached zero. I need to stop giving pies when I finish. Why does a variable never reach zero? Is there a better way to do this?

+4
source share
1 answer

It seems that decrementing an application variable will never cause it to drop below 1. I have no idea why this is. You can make application variables less than 1. This code, for example, runs the variable at -2 and increments it from there, which works fine:

 app:test += 1 from -2; 

Description just doesn't work like that ...

I would suggest just setting the score to 1 so that you pretend that 1 means 0. In this case, your application might look like this:

 rule morePies { select when web pageview ".*" if (app:pies > 1) then { notify("You get a pie", "Yay!"); } fired { app:pies -= 1 from 11; } } rules piesAreGone { select when web pageview ".*" if (app:pies <= 1) then { notify("No pies left", "Sorry."); } } 
+4
source

Source: https://habr.com/ru/post/1335660/


All Articles