In KRL can I have a persistent variable count down instead of up?
I want to have an app variable count down instead of up. I put the following in the postlude of one rule:
fired {
app:pies -= 1 from 10;
}
The variable app:pies
would count from 10 down to 1 but it never reached zero. I need to sto开发者_如何学Cp giving out pies when I run out. Why doesn't the variable ever reach zero? Is there a better way to do this?
It seems that decrementing an app variable won't ever cause it to go below 1. I have no idea why that is. You can make an app variables be less than 1. This code, for example, starts the variable at -2 and increments it from there, which works fine:
app:test += 1 from -2;
Decrementing just doesn't seem to work like that...
I would suggest just adjusting the count by 1, such that you pretend that 1 means 0. Your app might look like this in that case:
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.");
}
}
精彩评论