Najova

DocsBuilt-in functions

Blocks

Blocks run the lines between an opener and its closer, such as $if ... $endif.

$ifBlock

$if[condition]

Runs what follows when the condition holds, up to $elseif, $else or $endif.

if.naja
$let[hp;15]
$if[$get[hp] <= 0]
  $print[Game over]
$elseif[$get[hp] < 20]
  $print[Low health]
$else
  $print[All good]
$endif
najova run if.naja
Low health

$loopBlock

$loop[i;from;to] or $loop[i;from;to;step]

Runs what follows for i = from, from + 1 ... up to to.

loop.naja
$loop[i;1;10;3]
  $print[$get[i]]
$endloop
najova run loop.naja
1
4
7
10

$eachBlock

$each[item;list] or $each[key;value;table]

Runs what follows once for every item of a list (or key and value of a table).

each.naja
$each[name;score;$table[Ana;12;Ben;9]]
  $print[$get[name] scored $get[score]]
$endeach
najova run each.naja
Ana scored 12
Ben scored 9

$whileBlock

$while[condition]

Runs what follows again and again while the condition holds.

while.naja
$let[n;1]
$while[$get[n] < 100]
  $set[n;$get[n] * 3]
$endwhile
$print[$get[n]]
najova run while.naja
243

$break

$break

Leaves the $loop, $each or $while it is in.

break.naja
$each[n;$list[4;8;15;16]]
  $if[$mod[$get[n];2] == 1]
    $print[First odd number: $get[n]]
    $break
  $endif
$endeach
najova run break.naja
First odd number: 15

$continue

$continue

Goes on with the next round of the $loop, $each or $while it is in.

continue.naja
$loop[i;1;6]
  $if[$mod[$get[i];3] == 0]
    $continue
  $endif
  $print[$get[i]]
$endloop
najova run continue.naja
1
2
4
5

$tryBlock

$try

Runs what follows; when something in it fails, the script goes on at $catch instead of stopping.

try.naja
$try
  $print[$item[$list[1;2];5] + 1]
$catch[why]
  $print[Could not add: $get[why]]
$endtry
najova run try.naja
Could not add: Cannot do nil + number (maths needs numbers).