Fonctionnement des scripts
Structure d'un paquet, fonction d'entrée, lancement, arrêt et rechargement, imports, temporisation, erreurs, journalisation et JavaScript pris en charge.
8 archives dans cette catégorie
-
A package is a small set of JavaScript files with a fixed starting point, index.js, and not every file in it runs when a bot starts the package. What a package contains A package with a few files looks like this: index.js asterobot.json lib/chat.js lib/format.mjs File Required What it's for index.js Yes The entry module. Every script starts here. Other .js and .mjs files No Modules that index.js imports, directly or through other modules. They can sit at the root of the package or in
- 0 commentaires
- 3 vues
-
Every script starts in one function: the default export of the package's index.js. Asterobot calls it each time a bot starts the package, and the way you write it decides whether that start goes through. The default export export default async function behavior(launch) { // ... } Asterobot checks three things before and after calling it: Rule Error when it's broken index.js has a default export behavior module "library/my-first-script/1.0.0/index.js" has no unambiguous default export
- 0 commentaires
- 1 vue
-
A script runs from the moment a bot starts it until something stops it, and it keeps little from one run to the next. States and controls describes the same buttons from the player's side. Starting a script Where Control What it does Package editor Run Saves the package, stops the script the chosen bot is running, sets this package as the bot's package, then starts it. Bot's page, or its row in Bot Manager Play Starts the bot's package, or the inline script loaded last. It's disabled
- 0 commentaires
- 2 vues
-
Every file of a package is an ES module. Scripts reach Asterobot's functions, their own files and other packages through import statements, and through nothing else. The built-in modules Module Exports Reference asterobot:protocol send, request, wait, on, off, onTraffic, intercept asterobot:protocol asterobot:bot session, currentMap, disconnect, botDebug, botInfo, botWarn, botError asterobot:bot asterobot:timers sleep asterobot:timers asterobot:gamedata text, record, table, find,
- 0 commentaires
- 1 vue
-
A bot runs its script one piece of code at a time. Once you know how those pieces are scheduled, the 250 ms limit, long loops and the order of handlers stop being surprises. One piece of code at a time Each bot runs its own copy of the script, and bots run side by side without sharing anything. Inside one bot, a single piece of your code runs at any moment: the entry function, a handler, or the rest of an async function after an await. The next piece only starts once the current one has finish
- 0 commentaires
- 2 vues
-
Most mistakes in a script stop it until its next start. Knowing which ones do, where they show up and how their texts are built saves a lot of guessing. Where errors show up Where What it tells you The behavior stopped with an error, at the top of the bot's page The script started, then stopped because of an error. The alert shows the whole text, with Copy and Dismiss. The bot's Behavior badge, and its column in Bot Manager, say Failed. Couldn't start the behavior after Play, or Could
- 0 commentaires
- 1 vue
-
When a script doesn't do what you expect, its own output is usually the quickest way to find out why, once you know which of the two consoles it went to. Two places to write Functions Module Where the lines appear botDebug(), botInfo(), botWarn(), botError() asterobot:bot The bot's Console tab, as Script lines, at every level debug(), log(), info(), warn(), error(), also available on the console object asterobot:console Server > Console, and the terminal Asterobot runs in The bo
- 0 commentaires
- 3 vues
-
Scripts run modern JavaScript, with three constructs left out and a few built-in objects missing. JSDoc comments make what the editor tells you more precise. What works The syntax of JavaScript up to ES2022 works, apart from the three constructs in the next section. That includes: classes, with private fields such as #count and static blocks async functions and await, with Promise.all(), Promise.allSettled() and Promise.any() generators (function*) and for...of optional chaining ?., ?? an
- 0 commentaires
- 3 vues