Najova

DocsGuides

Values and names

A value is a number, some text, true, false, nil (nothing), a list or a table. Give a value a name to use it again.

Names

Make a name with $let, change it with $set, and read it with $get.

names.naja
$let[coins;50]
$set[coins;$get[coins] - 20]
$print[Coins left: $get[coins]]
najova run names.naja
Coins left: 30

A name made inside a block or a function belongs to it. Once the block ends, the name is gone.

inside.naja
$if[true]
  $let[secret;42]
$endif
$print[$get[secret]]
najova run inside.naja
inside.naja:4: There is no name secret here; make it first with $let[secret;value].

Maths

When a whole value is maths, Najova works it out. You can use + - * / %, brackets, and comparisons like >=. If anything in the value is plain text, the whole value stays text.

maths.naja
$let[price;4]
$print[$get[price] * 3]
$print[Three cost $get[price] * 3]
$print[Three cost $mul[$get[price];3]]
najova run maths.naja
12
Three cost 4 * 3
Three cost 12
The second line prints the sum as text, because the words make the value text. Use a function such as $mul inside text.

Text

Spaces at the start and end of a value are dropped. To keep them, put the whole value in quotes. To use ;, [, ] or $ in text, put \ before it.

text.naja
$let[padded;"   wide   "]
$print[Size: $count[$get[padded]] letters]
$print[Prices start at \$5\; delivery is free]
najova run text.naja
Size: 10 letters
Prices start at $5; delivery is free

Lists and tables

A list keeps values in order. Its first item is number 1. A table finds values by their keys. Read a table's value with a dot: $get[player.name].

bag.naja
$let[bag;$list[sword;rope]]
$add[$get[bag];lamp]
$print[$count[$get[bag]] items: $get[bag]]

$let[player;$table[name;Ari;gold;12]]
$set[player.gold;$get[player.gold] + 5]
$print[$get[player.name] has $get[player.gold] gold]
najova run bag.naja
3 items: [sword; rope; lamp]
Ari has 17 gold

See Lists and tables for every function that works on them.