Day 6 – Conditional Action Blocks and Else Postludes

Goal: Execute action based on condition then raise explicit event based on execution of action block

ruleset a60x45 {
  meta {
    name "Conditional action blocks and else postludes"
    author "Mike Grace"
    description <<
      showing off how to conditionaly fire an action block and using else postludes
    logging on

  rule maybe_fire_based_on_random_num {
    select when pageview ".*"
    pre {
      r = math:random(2);
    if (r == 0) then {
    fired {
      raise explicit event zero;
    } else {
      raise explicit event one;

  rule random_num_was_zero {
    select when explicit zero
      notify("Zero!","") with sticky = true;

  rule random_num_was_one {
    select when explicit one
      notify("One!","") with sticky = true;
  • 14 get random number of 0 or 1
  • 16 action block conditional – don’t forget the ‘then’!
  • 17 noop() is an action that does nothing
  • 19-23 postlude block
  • 19-20 if the action block fired because r did == 0 then the explicit event zero is raised
  • 21-22 if the action block did NOT fire because r did == 1 then the explicit event one is raised
  • 27 selects when the explicit zero event is raised

App run several times one using bookmarklet:

Get the bookmarklet to try it out yourself!

Gratuitous day 6 crazy face

About these ads
This entry was posted in Kynetx and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s