These words always mean what the table says, and can’t be used as names.
| Keyword | What it does |
|---|
as | Treats a value as another type, or renames an import. See Casts. |
as? | Treats a value as another type, or gives null. |
break | Leaves a loop. See break and continue. |
class | Declares a class. See Classes and objects. |
continue | Skips to a loop’s next pass. |
do | Starts a do-while loop, which runs at least once. |
else | The branch of if or when taken when nothing else matches. |
false, true | The two Boolean values. |
for | Goes over a range or a collection. See for. |
fun | Declares a function. See Functions and lambdas. |
if | Runs a branch when a condition holds, and gives back its value. |
in | Goes over something in a for, or checks that a value is in a range or collection. |
!in | Checks that a value is not in a range or collection. |
interface | Declares an interface. |
is | Checks a value’s type. After it, the value is that type. |
!is | Checks that a value is not of a type. |
null | No value. Only a type ending in ? can hold it. See Null safety. |
object | Declares a type with exactly one value. See Objects. |
package | Not written in a .rift file: a file’s package is its folder. See The folder is the package. |
return | Leaves a function. return@name leaves a block, such as a hook’s. |
super | The class a class extends, to call what it overrides. |
this | The object a function belongs to. In a hook’s block, the event. |
throw | Raises an error. See Exceptions. |
try | Runs a block whose errors catch handles. |
typealias | Gives a type another name. See Type aliases. |
val | Names a value that never changes. |
var | Names a value that can change. |
when | Picks the first matching branch. See when with a subject. |
while | Repeats while a condition holds. |
These are keywords only where the table says, and can be names elsewhere.
| Keyword | What it does |
|---|
by | Hands a property to something else to look after, as in val table by lazy { … }. |
catch | Handles an error thrown in a try. |
constructor | Declares another way to make an object of a class. |
field | Inside a property’s get or set, the value the property stores. |
finally | A block after try that always runs. |
get | Works out a property’s value each time it is read. |
import | Brings in a name from another package. See import. |
init | A block that runs when an object of a class is made. |
it | The one parameter of a lambda that doesn’t name it. |
set | Runs when a property is given a value. |
where | Sets more than one rule for a type parameter. |
Modifiers go before a declaration and change what it is.
| Modifier | What it does |
|---|
abstract | A class that can’t be made itself, or a member a subclass must provide. |
companion | An object inside a class that belongs to the class itself. |
const | A value fixed when the file is built, at the top level or inside an object or companion object. |
data | A class that holds values, compares by them and has copy. |
enum | A class with a fixed set of values. |
infix | A function called without the dot and brackets: "lobster" costs 50. |
inline | A function whose body is copied into each place that calls it. |
inner | A class inside another that can use the outer one’s members. |
lateinit | A class’s var that gets its value after the object is made. |
open | A class or member that others can extend or override. |
operator | A function that gives a type an operator such as + or []. |
out | A type parameter a class only gives out. |
override | Replaces a member inherited from a class or interface. |
public | Lets other files use a top-level declaration. A file with one is a library file. See Sharing code between files. |
reified | Lets an inline function use its type parameter at run time. |
sealed | A class with a fixed set of subclasses. |
tailrec | A function that calls itself last, run as a loop. |
value | A class that wraps one value. |
vararg | A parameter that takes any number of arguments. |
| Name | What it does |
|---|
node<K>() | On the first line, makes the script belong to a node of kind K that you place in Forge. |
self | In a node script, the node’s entity. |
on_ | The start of every hook’s name, such as on_login. See Gameplay hooks. |
on_self_ | The start of a hook about a node script’s own node. |
Logger.info("The guard is at its post: ${self === npc}.")
| Operator | What it does |
|---|
+, -, *, /, % | Arithmetic. + also joins strings and adds to collections. |
= | Gives a variable a value. |
+=, -=, *=, /=, %= | Changes a variable by a value. |
++, -- | Adds or takes away one. |
&&, ||, ! | And, or, not. |
==, != | Equal and not equal in value. |
===, !== | The same object, or not. |
<, >, <=, >= | Comparisons. |
[ ] | Reads or sets an item of a list or map. |
?. | Calls only when the value isn’t null. |
?: | Gives a fallback when the left side is null. |
!! | Says a value isn’t null, and throws if it is. |
:: | Refers to a function or class without calling it. |
.., ..< | A range, with or without its end. |
-> | Separates a lambda’s parameters from its body, and a when branch from its result. |
@ | Marks a label, as in return@on_login. |
$ | Puts a value in a string. |
_ | A lambda parameter you don’t use. |