Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: update screen shot

...

Before starting, visit the "Rulesets" tab for your pico, and notice that your pico has no entity variables for the "hello_world" ruleset.

Create You will create a rule and name it store_name. Have it select on event domain hello and event type name.

We'll have Have the rule expect an event attribute named "name". We will declare  


Include an entry in the array of "events" in your __testing shared name:


Code Block
{ "domain": "hello", "type": "name", "attrs": [ "name" ] }

Bind a variable for the name (also named "name") and log it, all in the prelude.  The When the rule store_name will  fires, have it send a directive named store_name with option name giving the passed parameter name we are going to set.  The directive will allow us to know that the rule is working without having to look at the logs.

Entity variables can only be set in the postlude. We use the always form of the postlude so that this postlude is always evaluated. Just mentioning the name of the entity variable (yet another "name") will cause it to be created when the rule fires. Notice that mutating an entity variable requires the ":=" operator.


Code Block
firstline35
linenumberstrue
  rule store_name {
    select when hello name
    pre{
      passed_name = event:attr("name").klog("our passed in name: ")
    }
    send_directive("store_name") with
      name = passed_name
    always{
      ent:name := passed_name
    }
  }

Also include this entry in the "events" section of your __testing shared name:

Code Block{ "domain": "hello", "type": "name", "attrs": [ "name" ] }

Notice that the identifier "name" appears in several different place in this rule, and plays different roles.

  • line 36 "name" is the event type
  • line 39 "name" is a local variable which is bound to the value of the passed-in attribute named "name"
  • line 41 "name" will be the name of the first of the "options" appearing in the directive and its value there will be the value bound in line 39
  • line 43 "ent:name" is the name of an entity variable which will be set to the value bound in line 39

With an entry for the hello/name event in place, when you refresh your pico's "Testing" tab, there will be a UI for sending the event which will trigger the new rule. Use this UI to send the event. Notice the directive returned by the rule, named "store_name".

Refresh the "Rulesets" tab for your pico, and you'll see the entity variable named "ent:name", which was created the first time it was used.

Now change the hello_world rule to default to our persistent name.

...