Aller au contenu
Afficher dans l'application

Une meilleure façon de naviguer. En savoir plus.

Asterobot

Une application plein écran sur votre écran d'accueil avec notifications push, badges et plus encore.

Pour installer cette application sur iOS et iPadOS
  1. Appuyez sur Icône de partage dans Safari
  2. Faites défiler le menu et appuyez sur Ajouter à l'écran d'accueil.
  3. Appuyez sur Ajouter dans le coin supérieur droit.
Pour installer cette application sur Android
  1. Appuyez sur le menu à trois points (⋮) dans le coin supérieur droit du navigateur.
  2. Appuyez sur Ajouter à l'écran d'accueil ou Installer l'application.
  3. Confirmez en appuyant sur Installer.

asterobot:parameters

(0 notes)

asterobot:parameters gives a script the current values of its package's settings: the ones declared with export const parameters and shown on the bot's Settings tab, under Package settings. Declarations describes how to declare them, and Read settings shows how to use them.

import { values, onChange, offChange } from "asterobot:parameters";

Whose settings

Each package gets its own copy of this module. Any file of a package that imports it reads that package's settings, declared in that package's index.js, and nothing else. A dependency reads its own settings, never those of the package that uses it, and no package can read another package's settings. Settings in dependencies explains how that looks on the bot's page.

values

values is a read-only object with one property per declared setting.

Declared type Value in values
bool A boolean
string A string
int A whole number. It's a regular number, not a BigInt, unlike 64-bit fields in game messages.
double A number
array An array of values of the of type
map An object whose keys are strings and whose values have the of type

The values are the ones saved for this bot, on top of the declared defaults. Settings are saved under the package's name, whatever its version, so they carry over when the bot moves to a new version. A saved value that no longer fits the declaration, because the setting was renamed, removed or given another type, is ignored, and the default applies.

values is live. When someone clicks Apply on the bot's page, the running script reads the new values from its next read on, without restarting. A package's settings are applied all at once, so a script never reads half of an edit.

Don't assign to values or delete from it. Package code always runs as a module, which JavaScript makes strict, so Asterobot's refusal throws: assigning a property throws a TypeError with 'Set' on a dynamic object returned false, and deleting one throws Could not delete property "<name>" of a dynamic object. Either way the setting keeps the value set on the bot's page.

Object.keys(values) lists the settings, in no particular order, and "name" in values tells whether a setting exists.

When Asterobot can't read the package's declarations, the bot's page shows Couldn't read this package's settings, and the script starts with no settings at all: values is empty, and every read returns undefined.

While Asterobot reads the declarations themselves, values is an empty object too, so a declaration can't depend on a setting's value.

onChange()

onChange(handler) returns a handle, { id }, where id is a BigInt.

Parameter Type Description
handler function Called with { name, value } for each setting whose value changed

When settings of this package are applied to the running script, handler runs once for each setting whose value actually changed, with the setting's name and its new value, of the type shown in the table above. Settings applied with the value they already had don't call it, and arrays and maps count as changed only when their content differs.

It doesn't run when the script starts, and it never runs for another package's settings. With several handlers, the order they run in isn't defined. Settings applied while no script runs are saved, and the next start reads them from values.

In the rare case where the script already has 32 operations pending when someone applies settings, the settings are saved, but the running script only gets them at its next start. See Limits.

An error in a handler stops the script:

What happened Text in the Problems alert
The handler threw parameters.onChange handler <number>: <error>
An async handler's promise rejected unhandled Promise rejection: <error>

onChange() throws a TypeError at once when:

Error Cause
parameters.onChange handler must be callable handler isn't a function
maximum behavior handlers reached 256 onChange() handlers are already registered. This count is separate from the message handlers of asterobot:protocol.

If the script is already stopping, onChange() throws the reason it's stopping.

onChange(({ name, value }) => {
  botInfo(`Setting ${name} is now ${value}`);
});

offChange()

offChange(handle) returns undefined.

It removes the handler that onChange() registered, given the handle it returned. It never throws: a handle that was already removed, or anything else, is ignored. It doesn't remove handlers registered with on(), onTraffic() or intercept(): use off() for those.

Types

Type Definition
ParameterScalar A boolean, a string or a number
ParameterValue A ParameterScalar, a read-only array of them, or a read-only object of them
ParameterChange { name: string, value: ParameterValue }, what onChange() handlers receive
ParameterSubscription { id: bigint }, the handle onChange() returns

When a value applied from the bot's page doesn't fit its declaration, nothing is saved and the page shows Couldn't apply the settings with the reason. Error messages lists those reasons.

Commentaires des utilisateurs

Aucun avis à afficher.

Compte

Navigation

Recherche

Recherche

Configurer les notifications push du navigateur

Chrome (Android)
  1. Appuyez sur l'icône de cadenas à côté de la barre d'adresse.
  2. Tap Autorisations → Notifications.
  3. Ajustez vos préférences.
Chrome (Desktop)
  1. Cliquez sur l'icône représentant un cadenas dans la barre d'adresse..
  2. Select Paramètres du site.
  3. Find Notifications et ajustez vos préférences.