# syntax basics

### comments

```csharp
// a single line comment

/*
a block comment
that can span multiple lines
*/
```

### blocks use braces, not indentation

```csharp
function example(a, b) {
    if (a > b) {
        return a
    } else {
        return b
    }
}
```

every `{` needs a matching `}`. there's no colon and indent syntax like skript

### declaring things at the top level

a script file is just a list of top level declarations:

```csharp
val maxPlayers = 8 // an immutable value
var currentRound = 0 // a mutable value

function helper(x) { // a plain function, callable from other functions
    return x * 2
}

@Katton.command(name = "start", permission = "admin")
function startGame(sender, args) { // a script command
    ...
}

@Katton.listen("player_join")
function onJoin(event) { // an event listener
    ...
}
```

`val`/`var` declared at the top level are evaluated **once**, when the script compiles

### functions never have typed parameters

```csharp
// INVALID and won't compile
function giveWand(sender: Player, args: List<String>) {
    ...
}
```

```csharp
// VALID
function giveWand(sender, args) {
    ...
}
```

there are **no type annotations anywhere**. the interpreter figures out what a parameter actually is from how it's used and where the function is called from (e.g. a `@Katton.command` handler's `sender` is always a `player` value, `args` is always a list of strings)

### two special annotations

```csharp
@Katton.command(name = "leapwand", permission = "admin")
function giveLeapWand(sender, args) {
    // must have EXACTLY these two parameters
}

@Katton.listen("player_rightclick")
function onLeap(event) {
    // must have EXACTLY this one parameter
}
```

### strings

```csharp
val name = "Steve"
val withEscapes = "line one\nline two\tafter a tab\n\"quoted\""
val concatenated = "count: " + 5 // -> "count: 5", numbers stringify automatically
```

only double quotes. `\n`, `\t`, `\"`, and `\\` are the supported escapes

### next!

* [variables & values](variables-and-values.md)
* [lists & maps](lists-and-maps.md)
* [operators](operators.md)
* [control flow](control-flow.md)
* [loops](loops.md)
* [functions](functions.md)
