set: changing an existing value

Syntax and values

set score = score + 1
set board[row] = 7
set player.score = 100
set players[index].stats.lives = 3

set updates an existing assignable name. The target must be rooted in an
identifier and may contain index and member suffixes. Plain name = value is
not assignment syntax.

The right-hand expression is evaluated before any index or member expressions
in the assignment target. This matters when those expressions call functions
with effects.

Functions, built-in functions, imported module namespaces, and imported module
members are read-only. A list index or map key must already exist; assignment
does not grow a list or add a map key.

Example

# language: en
let player = {"score": 10}
set player.score = player.score + 5
say player.score

Syntax and values · Built-ins · Programming guides