Difference between revisions of "Bot Playground/Built-in Functions/localStorage.on"
From SmartBots Developers Docs
(5 intermediate revisions by the same user not shown) | |||
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 | * entry - is the name of the key set | ||
* value - the value | * value - the value | ||
Line 17: | Line 17: | ||
{{API Variables Table End}} | {{API Variables Table End}} | ||
+ | |||
+ | |||
+ | == Limitations == | ||
+ | |||
+ | See [[Bot_Playground/Built-in_Functions/localStorage.set|localStorage.set()]] for storage limitations. | ||
== Comments == | == Comments == | ||
Line 42: | Line 47: | ||
exit(); | exit(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | How to run: | ||
# Launch the "Listener" script (it will keep running) | # Launch the "Listener" script (it will keep running) | ||
# Launch the "Initiator" script (it will run and stop) | # Launch the "Initiator" script (it will run and stop) | ||
− | # Now switch to the "Listener" script and check the runtime logs | + | # Now switch to the "Listener" script and check the runtime logs of "Listener" |
{{NavMenu}} | {{NavMenu}} | ||
+ | __NOTOC__ |
Latest revision as of 12:38, 14 August 2024
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
|
Limitations
See localStorage.set() for storage limitations.
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
To see how localStorage.on("update") works you'll need two scripts:
The "Listener" script:
localStorage.on("update", function(entry, value, script) {
console.log("localStorage got updated:", entry, "=", value, "by script", script);
exit();
});
The "Initiator" script:
localStorage.set("data", "data from 1");
exit();
How to run:
- Launch the "Listener" script (it will keep running)
- Launch the "Initiator" script (it will run and stop)
- Now switch to the "Listener" script and check the runtime logs of "Listener"