Difference between revisions of "Bot Playground/Built-in Functions/userSettings.*"
From SmartBots Developers Docs
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Allows accessing the settings specified by the script user.</onlyinclude> <syntaxhighlight lang="javascript"> const value = user...") |
(Add userSettings defaults example.) |
||
(One intermediate revision by one other user not shown) | |||
Line 7: | Line 7: | ||
User settings are intended to be used within the scripts you sell at [[Bot_Playground/Store|Bots Store]]. However, they can be used for your own scripts, too. | User settings are intended to be used within the scripts you sell at [[Bot_Playground/Store|Bots Store]]. However, they can be used for your own scripts, too. | ||
+ | |||
+ | |||
+ | == Example: Setting defaults == | ||
+ | An easy way to set defaults is to use the Object.assign() javascript function. | ||
+ | <syntaxhighlight lang="javascript"> | ||
+ | //Define the default settings here. | ||
+ | const defaultSettings = { | ||
+ | greetingMessage: "Hello, welcome!", | ||
+ | repeatCount: 2, | ||
+ | enableLogging: false | ||
+ | }; | ||
+ | |||
+ | //Merge defaults with any values provided by the user. | ||
+ | const settings = Object.assign({}, defaultSettings, userSettings); | ||
+ | |||
+ | //Access the settings in the following way: | ||
+ | console.log(settings.greetingMessage); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | == Learn more == | ||
Check the [[Bot_Playground/Store/User_settings|User Settings]] reference for information how to define and set user settings. | Check the [[Bot_Playground/Store/User_settings|User Settings]] reference for information how to define and set user settings. |
Latest revision as of 13:21, 5 August 2025
Allows accessing the settings specified by the script user.
const value = userSettings.someUserVar;
User settings are intended to be used within the scripts you sell at Bots Store. However, they can be used for your own scripts, too.
Example: Setting defaults
An easy way to set defaults is to use the Object.assign() javascript function.
//Define the default settings here.
const defaultSettings = {
greetingMessage: "Hello, welcome!",
repeatCount: 2,
enableLogging: false
};
//Merge defaults with any values provided by the user.
const settings = Object.assign({}, defaultSettings, userSettings);
//Access the settings in the following way:
console.log(settings.greetingMessage);
Learn more
Check the User Settings reference for information how to define and set user settings.