Zuweisung
Es gibt nur eine Möglichkeit, eine Variable zuzuweisen: $x = 3. Das $ gehört überall, wo es geschrieben steht, zum Namen der Variablen, sodass sie so gesetzt wird, wie sie gelesen wird. Die erste Zuweisung deklariert $x im aktuellen Block; danach ändert dieselbe Anweisung sie, auch aus einem verschachtelten Block oder einer Funktion heraus. Andere Operatoren aktualisieren eine bestehende 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 und set werden in .kscript-Dateien nicht verwendet; sie zu schreiben ist ein Fehler, der darauf hinweist, das Wort wegzulassen. In XML behalten sie ihre Bedeutung (<let> deklariert im aktuellen Gültigkeitsbereich, <set> ändert), und kscript convert wählt das richtige aus.