3

I have the following in my global block:

test = defaction(){
    if(5>10) then {
        notify("yes","yes");    
    }
}

Then I also have the following rule:

rule tester {
    select when pageview ".*"
    test();
}

I am expecting that the notify will never happen, as 5 will never be greater than 10. However, it runs on every single page. I am sure that I am doing it wrong, although it feels right.

halfer
  • 19,824
  • 17
  • 99
  • 186
frosty
  • 21,036
  • 7
  • 52
  • 74

1 Answers1

2

Predicates (such as if (5>10) then are not part of the action block. As such, including predicatees in a defaction doesn't make sense. You'll have to write it more like this:

global {
    test = defaction(){
        notify("yes","yes");    
    }
}

rule tester {
    select when pageview ".*" setting ()
    if (5>10) then {
        test();
    }
}

The if...then construct fulfills the same function as, say, the every construct: it wraps the action block.

Steve Nay
  • 2,819
  • 1
  • 30
  • 41
  • You are correct. Conditions must be placed outside a defaction. If you want neat features allowing either/or action behavior, bug @pjw about 'Non-random Choose'. – TelegramSam Mar 29 '11 at 15:55