Skip to content

Instantly share code, notes, and snippets.

@snay2
Created February 25, 2012 22:50

Revisions

  1. snay2 renamed this gist Feb 25, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. snay2 renamed this gist Feb 25, 2012. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions gistfile1.js → gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -36,11 +36,11 @@
    // When the user clicks the Submit button on the form, save that value to
    // the entity variable map
    rule assign_key {
    select when web submit
    pre {
    val = event:param("val");
    }
    notify("Maps", "I'm assigning the value '#{val}' to the key 'mykey' in the entity variable 'mymap'.");
    select when web submit
    pre {
    val = event:param("val");
    }
    notify("Maps", "I'm assigning the value '#{val}' to the key 'mykey' in the entity variable 'mymap'.");
    fired {
    set ent:mymap{"mykey"} val;
    }
  3. snay2 created this gist Feb 25, 2012.
    72 changes: 72 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    ruleset a163x153 {
    meta {
    name "Maps"
    description <<
    Simple example of creating and using maps
    >>
    author "Steve Nay"
    logging off
    }

    dispatch { }

    global { }

    // A simple rule to fetch the value from an entity variable map
    // and allow the user to modify it.
    rule display_value {
    select when web pageview ".*"
    pre {
    val = ent:mymap{"mykey"};
    msg = <<
    The current value is #{val}.<br />
    Set it here:
    <form id="myform">
    <input name="val" />
    <input type="submit" />
    </form>
    >>;
    }
    {
    notify("Maps", msg) with sticky=true;
    watch("#myform", "submit");
    }
    }

    // When the user clicks the Submit button on the form, save that value to
    // the entity variable map
    rule assign_key {
    select when web submit
    pre {
    val = event:param("val");
    }
    notify("Maps", "I'm assigning the value '#{val}' to the key 'mykey' in the entity variable 'mymap'.");
    fired {
    set ent:mymap{"mykey"} val;
    }
    }

    ///////////////////////////////////////////////////
    // A simpler rule to demonstrate only getting. Test this and the following
    // rule by deploying this app and installing it your personal event network.
    // Then use the Kynetx Event Console to raise the value:fetch and value:store events.
    rule fetch_value {
    select when value fetch
    pre {
    val = ent:mymap{"mykey"};
    }
    send_directive("text") with body="#{val}";
    }

    // A simpler rule to demonstrate only setting
    rule set_value {
    select when value store
    pre {
    val = event:param("val");
    }
    noop();
    fired {
    set ent:mymap{"mykey"} val;
    }
    }
    }