syntax basics
comments
blocks use braces, not indentation
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:
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
// INVALID and won't compile
function giveWand(sender: Player, args: List<String>) {
...
}
// 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
@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
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