Skip to content

Keyword reference

These words always mean what the table says, and can’t be used as names.

KeywordWhat it does
asTreats a value as another type, or renames an import. See Casts.
as?Treats a value as another type, or gives null.
breakLeaves a loop. See break and continue.
classDeclares a class. See Classes and objects.
continueSkips to a loop’s next pass.
doStarts a do-while loop, which runs at least once.
elseThe branch of if or when taken when nothing else matches.
false, trueThe two Boolean values.
forGoes over a range or a collection. See for.
funDeclares a function. See Functions and lambdas.
ifRuns a branch when a condition holds, and gives back its value.
inGoes over something in a for, or checks that a value is in a range or collection.
!inChecks that a value is not in a range or collection.
interfaceDeclares an interface.
isChecks a value’s type. After it, the value is that type.
!isChecks that a value is not of a type.
nullNo value. Only a type ending in ? can hold it. See Null safety.
objectDeclares a type with exactly one value. See Objects.
packageNot written in a .rift file: a file’s package is its folder. See The folder is the package.
returnLeaves a function. return@name leaves a block, such as a hook’s.
superThe class a class extends, to call what it overrides.
thisThe object a function belongs to. In a hook’s block, the event.
throwRaises an error. See Exceptions.
tryRuns a block whose errors catch handles.
typealiasGives a type another name. See Type aliases.
valNames a value that never changes.
varNames a value that can change.
whenPicks the first matching branch. See when with a subject.
whileRepeats while a condition holds.

These are keywords only where the table says, and can be names elsewhere.

KeywordWhat it does
byHands a property to something else to look after, as in val table by lazy { … }.
catchHandles an error thrown in a try.
constructorDeclares another way to make an object of a class.
fieldInside a property’s get or set, the value the property stores.
finallyA block after try that always runs.
getWorks out a property’s value each time it is read.
importBrings in a name from another package. See import.
initA block that runs when an object of a class is made.
itThe one parameter of a lambda that doesn’t name it.
setRuns when a property is given a value.
whereSets more than one rule for a type parameter.

Modifiers go before a declaration and change what it is.

ModifierWhat it does
abstractA class that can’t be made itself, or a member a subclass must provide.
companionAn object inside a class that belongs to the class itself.
constA value fixed when the file is built, at the top level or inside an object or companion object.
dataA class that holds values, compares by them and has copy.
enumA class with a fixed set of values.
infixA function called without the dot and brackets: "lobster" costs 50.
inlineA function whose body is copied into each place that calls it.
innerA class inside another that can use the outer one’s members.
lateinitA class’s var that gets its value after the object is made.
openA class or member that others can extend or override.
operatorA function that gives a type an operator such as + or [].
outA type parameter a class only gives out.
overrideReplaces a member inherited from a class or interface.
publicLets other files use a top-level declaration. A file with one is a library file. See Sharing code between files.
reifiedLets an inline function use its type parameter at run time.
sealedA class with a fixed set of subclasses.
tailrecA function that calls itself last, run as a loop.
valueA class that wraps one value.
varargA parameter that takes any number of arguments.
NameWhat it does
node<K>()On the first line, makes the script belong to a node of kind K that you place in Forge.
selfIn 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.
scripts/lumbridge/guard.rift
node<Npc>()
on_self_spawn { npc ->
Logger.info("The guard is at its post: ${self === npc}.")
}
OperatorWhat 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.