...
One of the main ways to start code on creation of a pico is by executing code on ruleset installation. Wrangler raises the wrangler:ruleset_added event whenever you install a ruleset on a pico using wrangler (it uses the wrangler:install_rulesets_requested event). One of the attributes that wrangler:child_creation takes is a "rids_to_install"/"rid" parameter. When creating a new pico, Wrangler will install the list of rulesets given in this attribute in the new pico as it is created. Wrangler will then raise wrangler:ruleset_added as normal, which you can select on and run code with.
...
- All the valid rulesets given to "rids_to_install" will be guaranteed to be installed by the time wrangler:ruleset_added is raised in a new pico
- Any attributes given in the wrangler:child_creation event will be in the attributes for the wrangler:ruleset_added event(s). This is a useful way to give parameters to a new child pico's rulesets.
- Listing initialization rules first in rulesets is good practice, as it is the first thing a ruleset will ever do.
Run Code In New Child Example
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// Creates a new child with the "example" ruleset installed and passes an attribute named "testParam"
rule newExampleChild {
select when example new_child
always {
raise wrangler event "child_creation" attributes {
"rids":"test",
"testParam":"hello"
}
}
}
// In the newly created child this rule will run
rule inNewChild {
select when wrangler ruleset_added where rids >< meta:rid
pre {
paramFromParent = event:attr("testParam").klog("Should be 'hello'")
}
always {
ent:initial_state := {} // Set a desired initial state of entity variables
}
} |
Create Channel On Installation Example
...