Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix line number

...


Code Block
firstline35
linenumberstrue
  rule store_name {
    select when hello name
    pre{
      name = event:attr("name").klog("our passed in name: ")
    }
    send_directive("store_name") with
      name = name
    always{
      ent:name := 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 38 "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.

...