# ThicketScript documentation Source: https://thicketscript.com/docs/ --- URL: https://thicketscript.com/docs/start/ # Getting started ThicketScript is a language built from the ground up to make games. It reads like TypeScript, has its own type system, and runs on its own virtual machine. One program, `thicket`, runs your code, checks it, formats it, debugs it and builds it into a standalone program. This section takes you from nothing to a program you can share: 1. **Install** `thicket` (this page). 2. [Your first script](./first-script): write a `.tks` file and run it. 3. [Your first window](./first-window): open a window and put a sprite in it. 4. [Checking your code](./check): find type errors before you run anything. 5. [Building a program](./build-executable): turn a project into a folder you can ship. ## Install ::: info Downloads are coming soon The [download page](/download) is where `thicket` for Windows, macOS and Linux, plus the IDE plugin, will land. ::: Installing is one program, `thicket`, on your `PATH`, with nothing else to install: the compiler, the virtual machine, the standard library, the 2D module and the language server all live inside it. Once it is installed, this prints the version: ```sh thicket version ``` And this lists every command: ```sh thicket help ``` ## The commands you will use most | Command | What it does | |---|---| | `thicket new ` | Make a new project folder from a template. | | `thicket run` | Run a script or a project. | | `thicket check` | Type-check without running anything. | | `thicket watch` | Run, and run again whenever a file changes. | | `thicket fmt ` | Format a source file. | | `thicket build` | Package a project as a standalone program. | | `thicket debug` | Run with a debugger attached. | `thicket help ` prints the full reference for any one of them. ## Editor support `thicket lsp` is a built-in language server. The JetBrains plugin starts it for you and gives you autocomplete, type checking, go-to-definition and error highlighting as you type. Next: [your first script](./first-script). --- URL: https://thicketscript.com/docs/start/build-executable # Building a program ```sh thicket build ``` `thicket build` turns a project into a standalone program. The result runs on a machine with no `thicket`, no source code and no `thicket_packages/` folder. ## Try it ```sh thicket new hello cd hello thicket build ./build/hello ``` ```text hello from thicket ``` ## What you get The output goes to `build/` inside the project, replaced on each build: ```text build/ hello the program (a prebuilt runtime) bundle.tbc your compiled code and its frozen config package-receipt.json a record of every file that was placed ``` The program file is a prebuilt runtime. `bundle.tbc` is your compiled bytecode. Keep them side by side. - A **console app** gets the console runtime. - A **window app** (a project with a `window` section) gets the window runtime, in a flat folder you can zip and share. ## Ship your assets Only what the `assets` field lists ships with the program: ```json5 { entry: "app.tks", window: { title: "My Game" }, assets: ["assets/**"], } ``` Each file keeps the path it has in your project, so a path like `assets/player.png` means the same thing in `thicket run` and in the built program. ## Give your app an id `thicket build` warns when `thicket.json` has no `id`. Without one, the app's save and cache folders are named after the project folder, so two projects in folders with the same name would share them. Set an id before you ship. ## Useful flags | Flag | What it does | |---|---| | `--out ` | Write somewhere other than `build/`. A folder that is not empty is refused unless you add `--force`. | | `--release` | Drop the source map and function names. | | `--strategy ` | Choose how the program is packaged. | | `--list-strategies` | Show the strategies that fit this project. | ## Ship a fix without rebuilding everything The runtime is not tied to one bundle. A `bundle.tbc` from a later build of the same project, made with the same `thicket` version, can be dropped over the old one and runs the new code. Changed assets have to be copied too. Platforms, strategies and asset options are covered in [Building for each platform](/docs/build/). --- URL: https://thicketscript.com/docs/start/check # Checking your code ```sh thicket check ``` `check` type-checks and compile-checks a program. Nothing runs and nothing is written. It prints `ok` when the program is clean. Otherwise it prints each diagnostic with its file, line, column and severity (`error`, `warning` or `hint`). It exits with code 1 when there is an error. Warnings and hints alone do not fail the check. Like `run`, it takes a file, a project folder, or nothing (the nearest `thicket.json` above the current folder): ```sh thicket check thicket check app.tks thicket check ./mygame ``` ## What it catches Save this as `oops.tks`: ```ts let score: int = "ten"; ``` ```sh thicket check oops.tks ``` ```text oops.tks(1,5): error: Cannot assign "ten" to int (variable 'score') oops.tks(1,5): hint PF012: variable 'score' is declared but never used ``` The checker also reports: - missing type annotations on variables and missing return types on functions (warning `PF071`), - unused variables (a hint), - calls with the wrong number or type of arguments, - members that a class or interface does not declare, - a class that says `implements` but leaves a member out, - `await` in the wrong place, and other async mistakes, - a `switch strict` that misses an enum member. `check` also reports everything `run` would refuse at compile time, so a clean `check` means the program compiles. ## Window apps are checked too You can check a window app on a machine with no display. `check` never opens a window, so it is a good fit for a build server or a pre-commit hook. ## In your editor The JetBrains plugin runs the same checker through `thicket lsp` and underlines problems as you type. ## Formatting ```sh thicket fmt app.tks thicket fmt --check app.tks ``` `fmt` formats a file in place and keeps your comments. `--check` writes nothing and exits 1 when the file is not formatted. ## Silencing one line When a warning is wrong for one line, suppress it on the line before. The code in brackets limits it to one diagnostic: ```ts // @thicket-ignore-next-line [PF078] const y: int = legacyRect.width; ``` Next: [building a program](./build-executable). --- URL: https://thicketscript.com/docs/start/first-script # Your first script ## One file Save this as `hello.tks`: ```ts const name: string = "world"; console.log("Hello, " + name + "!"); ``` Run it: ```sh thicket run hello.tks ``` ```text Hello, world! ``` A `.tks` file runs from top to bottom. You do not need a project file for a quick script. Two things to notice already: - **Every declaration has a type.** `const name: string`, not `const name`. The checker warns when a type is missing. - **Every statement ends with a semicolon.** ## A little more Template strings, typed arrays and loops all look the way you expect: ```ts const name: string = "ThicketScript"; const version: int = 1; console.log(`Hello from ${name} v${version}!`); const items: Array = ["fast startup", "typed numbers", "batteries included"]; for (const item of items) { console.log(` - ${item}`); } ``` ```text Hello from ThicketScript v1! - fast startup - typed numbers - batteries included ``` ## A project Real programs live in a project: a folder with a `thicket.json` (or `thicket.json5`) file. Make one with `thicket new`: ```sh thicket new hello cd hello thicket run ``` `thicket new` writes three files: ```text hello/ .gitignore app.tks thicket.json5 ``` The project file names the entry file: ```json5 { "entry": "app.tks" } ``` And `app.tks` holds a class with a `static main()` method: ```ts class ConsoleApp { static main(): void { console.log("hello from thicket"); } } ``` When the entry file declares a class with `static main()`, `thicket run` runs the file's top-level code first, then calls that `main`. A plain `function main()` at the top level is ordinary code and is never called for you. `main` can also take the command-line arguments and return an exit code: ```ts class App { static main(args: Array): int { console.log("started with " + args.length + " arguments"); return 0; } } ``` Pass arguments after `--`: ```sh thicket run -- --verbose --level=3 ``` ## Templates `thicket new