할당
변수에 값을 할당하는 방법은 한 가지뿐입니다: $x = 3. $는 어디에 쓰이든 변수 이름의 일부이므로, 읽는 그대로 값이 설정됩니다. 처음 할당하면 현재 블록에 $x가 선언되며, 그 이후에는 같은 문장으로 값을 바꿀 수 있습니다. 중첩된 블록이나 함수 안에서도 마찬가지입니다. 다른 연산자는 이미 존재하는 변수를 갱신합니다: $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 및 set는 .kscript 파일에서 사용하지 않아요. 이를 작성하면 해당 단어를 삭제하라는 오류가 표시돼요. XML에서는 본래 의미를 유지해요(<let>는 현재 범위에 선언하고, <set>는 값을 변경해요). kscript convert는 둘 중 올바른 것을 선택해요.