Difference between revisions of "Bot Playground/Built-in Functions/localStorage.on"
From SmartBots Developers Docs
Line 11: | Line 11: | ||
{{API Variable Group|Input}} | {{API Variable Group|Input}} | ||
{{API Variable|eventName|yes}} the name of the event. Currently only supported event is ''"update"'' | {{API Variable|eventName|yes}} the name of the event. Currently only supported event is ''"update"'' | ||
− | {{API Variable|callback|yes}} the callback function to fire on event | + | {{API Variable|callback|yes}} the callback function to fire on event: function(entry, value, script) where |
+ | * entry - is the name of the key set | ||
+ | * value - the value | ||
+ | * script - the name of the script which did the change | ||
{{API Variables Table End}} | {{API Variables Table End}} | ||
Line 24: | Line 27: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
− | localStorage.on("update", function(entry, value) { | + | localStorage.on("update", function(entry, value, script) { |
− | console.log("localStorage got updated:", entry, "=", value); | + | console.log("localStorage got updated:", entry, "=", value, "by script", script); |
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{NavMenu}} | {{NavMenu}} |
Revision as of 21:59, 14 July 2018
Adds the event callback on localStorage. Also check localStorage.set().
localStorage.on(eventName, callback);
Reference
This command accepts the following parameters:
Variable | Required | Description
| |
---|---|---|---|
Input: | |||
eventName | yes | the name of the event. Currently only supported event is "update" | |
callback | yes | the callback function to fire on event: function(entry, value, script) where
|
Comments
Use this function if you want to know when other scripts do localStorage.set().
Important: the "update" event does not react on localStorage.set() calls in current script.
Example
localStorage.on("update", function(entry, value, script) {
console.log("localStorage got updated:", entry, "=", value, "by script", script);
});