Script Logic in BAS: Variables, Conditions and Loops
The Script Logic module in Browser Automation Studio — conditions, loops, variables, functions and flow control that turn a linear recording into a real program.
Recording clicks gets you a straight line. The Script Logic module is what bends that line into a program — branching, looping, remembering values and reporting success or failure. It’s the layer that separates a macro from real automation.
Conditions and loops
The core of any logic is choosing and repeating:
- IF — branch on a condition: do one thing when it’s true, another when it’s false.
- WHILE / FOR / FOREACH — repeat a block: while a condition holds, a fixed number of times, or once per item in a list.
- Break / Continue — stop a loop early, or skip to its next iteration.
This is how you process a list of accounts, retry until something appears, or handle “if logged in, skip login.”
Variables, local and global
Logic needs memory. BAS gives you two scopes:
- Set variable / Increment variable — ordinary variables, scoped to where you use them. Each thread keeps its own.
- Set global variable / Increment global variable — values shared across the whole script and every thread. Use these for counters and settings many threads read; use locals for per-account state so threads don’t clash.
Reporting a thread’s outcome
Each thread should end with a verdict, and the logic module provides it:
- Success — finish the thread’s work as a success.
- Fail — finish it as a failure.
- Abort script — stop the whole script.
These verdicts are what feed counters and the Resources system’s success/failure logic, so a run knows how many accounts actually worked.
Flow control and error handling
- Set label / Go to label — jump to a marked point in the flow when structured loops aren’t enough.
- Ignore errors — let a block fail without killing the thread, so you can branch on the failure instead of crashing.
A production bot is mostly this: not the happy path, but the branches that catch when an element is missing, a login fails or a page times out.
Calling functions
The logic module is also where you invoke your own functions:
- Call function — run a function you’ve built.
- Get function parameter — read a value passed into it.
- Return — hand a result back to the caller.
- Call function in multiple threads — run the same function in parallel to raise throughput.
Conditions, loops, variables and function calls are the whole vocabulary of programming, exposed visually. Master them and you stop recording macros and start writing software that happens to be assembled from blocks.
FAQ
How do conditions and loops work in BAS?
The Script Logic module provides IF for branching and WHILE, FOR and FOREACH for loops, plus Break and Continue to control them. You assemble real program flow visually instead of recording a single linear path.
What is the difference between a variable and a global variable in BAS?
A normal variable lives within its scope, while a global variable is shared across the whole script and all threads. Use globals for values many threads must read, and locals for per-thread state.
- Browser Automation Studio: The Complete Practical GuideGuide
- Building Your First Bot in Browser Automation StudioA step-by-step walkthrough of creating your first working BAS bot — from a blank project to a flow that navigates, extracts data, and runs in multiple threads.
- Setting Up Proxies in Browser Automation StudioHow to configure proxies in BAS the right way — proxy types, per-thread assignment, rotation, and the checks that keep multi-account bots from getting flagged.
- Finding Elements in BAS: Selectors That Don't BreakHow element search works in Browser Automation Studio — CSS vs XPath selectors, why recorded ones break, and how to write selectors that survive page changes.