DocsBuilt-in functions
Files and the computer
Only in najova run, not in game scripts. With --safe, scripts can only reach their own folder and cannot use the web.
$readFilenajova run only
$readFile[path]
The text of a file (paths start at the script's folder).
$print[$readFile[notes.txt]]Buy milk
$writeFilenajova run only
$writeFile[path;text]
Writes the text to a file, in place of what was in it.
$writeFile[save.txt;level 3]
$print[$readFile[save.txt]]level 3
$appendFilenajova run only
$appendFile[path;text]
Adds the text to the end of a file.
$writeFile[log.txt;started\n]
$appendFile[log.txt;finished]
$print[$readFile[log.txt]]started finished
$existsnajova run only
$exists[path]
true when there is a file or folder at the path.
$print[$exists[nothing-here.txt]]false
$filesnajova run only
$files or $files[folder]
A list of the names in a folder (the script's folder when none is given).
$each[name;$files[photos]]
$print[$get[name]]
$endeacha.png b.png
$makeFoldernajova run only
$makeFolder[path]
Makes a folder (and the folders it is in).
$makeFolder[saves/slot1]
$print[$exists[saves/slot1]]true
$deleteFilenajova run only
$deleteFile[path]
Deletes a file.
$writeFile[old.txt;x]
$deleteFile[old.txt]
$print[$exists[old.txt]]false
$envnajova run only
$env[name]
An environment value, like $env[DISCORD_TOKEN] (nil when it is not set), so secrets stay out of scripts.
$let[token;$env[DISCORD_TOKEN]]
$if[$get[token] == nil]
$error[Set DISCORD_TOKEN first.]
$endif
$argsnajova run only
$args
A list of what was written after the script's name: najova run bot.naja a b.
$print[Hello $item[$args;1], you are $item[$args;2]]Hello Sam, you are 12
$exitnajova run only
$exit or $exit[code]
Ends the program at once (code 0 means all went well).
$print[Before]
$exit[0]
$print[Never printed]Before
$helpernajova run only
$helper
In an extension that names a helper program: that program (started once). $call[helper.name;values...] asks it, $on[helper.Event;data] hears it.
$call[helper.render;card.png]
$on[helper.Done;file]
$print[Made $get[file]]
$endon
$fetchnajova run only
$fetch[url] or $fetch[url;options]
A web request; gives a table with status, ok, text and headers. Options: $table[method;POST;body;...;headers;$table[...]].
$let[answer;$fetch[https://example.com]]
$if[$get[answer.ok]]
$print[Got $count[$get[answer.text]] letters]
$else
$print[Failed: $get[answer.status]]
$endif