Skip to main content
SAM Script is the built-in programming environment inside SAM Studio. It gives you three ways to write programs for your SAM Labs hardware: a visual Blocks editor, a JavaScript text editor, and a Python text editor. You can switch between these modes at any time, and SAM Studio will do its best to translate your work across them.

Editor modes

SAM Script offers three editing modes. Each mode is suited to a different level of experience or workflow.

Blocks

Drag and drop visual blocks to build your program. A live code preview shows the equivalent JavaScript as you work — a great way to learn how code maps to visual logic.

JavaScript

Write JavaScript directly in a text editor. Full access to the SAM object API, async/await patterns, loops, and conditions. Ideal for students comfortable with text-based coding.

Python

Write Python in a clean text editor. Uses the sam module with snake_case methods. A natural fit if you already know Python from school or other projects.

Switching modes

The mode toggle sits at the top of the editor. Click Blocks, JavaScript, or Python to switch.
Switching from Blocks to JavaScript or Python converts your visual program into code automatically. Switching back from code to Blocks may not always be possible if your code contains patterns the Blocks editor cannot represent — SAM Studio will warn you before any work is lost.

The toolbar

The toolbar runs along the top of the editor and gives you quick access to the most important actions:
ButtonWhat it does
RunUploads and executes your program on the connected SAM hardware.
StopHalts the currently running program.
SaveSaves the project to your local storage.
SAM Script saves your work locally on this device. Always click Save before closing SAM Studio or switching projects — unsaved changes cannot be recovered.

The block palette

In Blocks mode, the panel on the left side of the screen is the block palette. It organises available blocks into categories:
  • Hardware — blocks for your connected SAM devices (LEDs, motors, buttons, sensors, and more)
  • Control Flow — if/else branches, wait blocks, and program start triggers
  • Variables — create and update named values in your program
  • Logic — comparisons and boolean operators (AND, OR, NOT)
  • Loops — repeat, while, and for-each structures
Drag any block from the palette onto the canvas to add it to your program. Blocks snap together automatically when they are compatible.

The canvas and code area

The large panel on the right is where you build or write your program:
  • In Blocks mode, this is the canvas — a free-form workspace where you connect blocks together.
  • In JavaScript or Python mode, this is a text editor with syntax highlighting, line numbers, and basic autocomplete for SAM APIs.
In Blocks mode, a collapsible code preview panel shows the JavaScript equivalent of your current block arrangement. Use it to build intuition for how visual logic translates into real code.

Console output

The Console panel sits at the bottom of the editor. It displays:
  • Output from console.log() (JavaScript) or print() (Python) calls in your program
  • Runtime errors and connection messages
  • Confirmation messages when your program starts and stops
Click the Clear button inside the console to remove old output before a new run.

Creating your first SAM Script project

1

Open SAM Studio and start a new project

Launch SAM Studio. From the home screen, click New Project.
2

Select SAM Script

In the project type picker, choose SAM Script. This opens the script editor rather than the flow-based canvas.
3

Give the project a name

Type a name for your project in the dialog that appears, then click Create. Choose something descriptive — you can always rename it later.
4

Choose your mode

At the top of the editor, select the mode you want to start in: Blocks, JavaScript, or Python. Not sure which to pick? Start with Blocks and switch to code when you feel ready.
5

Connect your hardware

Make sure your SAM Labs blocks are powered on and in range. SAM Studio will detect them automatically. You’ll see connected blocks listed in the Hardware section of the block palette (Blocks mode) or available via the SAM.connect() / sam.connect() API (code modes).
6

Click Run to execute your program

When you’re ready, click the Run button in the toolbar. SAM Studio sends your program to the hardware and begins executing it. Watch the Console for output and any error messages.
If a block doesn’t respond when you click Run, check the Console for a connection error. Try turning the block off and on again, then clicking Run once more.