Assignment
There is one way to assign a variable: $x = 3. The $ is part of the variable's name wherever it is written, so it is set the way it is read. The first assignment declares $x in the current block; after that, the same statement changes it, including from inside a nested block or a function. Other operators update an existing variable: $total += 1, $name ??= 'guest', $point.x = 3, $list[0] = 'a'.
<let name="total" value="0" />
<for each="item" in="$cart">
<set name="total" op="+=" value="$item.price" /> <!-- changes the total above -->
<let name="line" value="$item.name" /> <!-- new: only exists inside the loop -->
</for>
<const name="tax" value="0.2" /> <!-- can't be changed -->
<let name="count" type="int" value="$raw" /> <!-- declared with a type (converted, or an error) -->$total = 0
for item in $cart {
$total += $item.price // changes the total above
$line = $item.name // new: only exists inside the loop
}
const $tax = 0.2 // can't be changed
$count: int = $raw // declared with a type (converted, or an error)let and set aren't used in .kscript files; writing them is an error that says to drop the word. In XML they keep their meaning (<let> declares in the current scope, <set> changes), and kscript convert picks the right one.