From 33bf24fa860ae93b2498b22270bc7ea106a9579b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 3 Dec 2020 08:05:37 +0000 Subject: [PATCH] Merge docs for 'added list_files, fixes #589' --- docs/scarpet/Full.md | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index eb470336..bd8c1ae3 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -4571,13 +4571,15 @@ Available output types: ### `read_file(resource, type)` ### `delete_file(resource, type)` ### `write_file(resource, type, data, ...)` +### `list_files(resource, type)` With the specified `resource` in the scripts folder, of a specific `type`, writes/appends `data` to it, reads its - content, or deletes the resource. + content, deletes the resource, or lists other files under this resource. Resource is identified by a path to the file. A path can contain letters, numbers, characters `-`, `+`, or `_`, and a folder separator: `'/'`. Any other characters are stripped -from the name. Empty descriptors are invalid. Do not add file extensions to the descriptor - extensions are inferred +from the name. Empty descriptors are invalid, except for `list_files` where it means the root folder. + Do not add file extensions to the descriptor - extensions are inferred based on the `type` of the file. Resources can be located in the app specific space, or a shared space for all the apps. Accessing of app-specific @@ -4592,33 +4594,26 @@ specific data directory is under `world/scripts/foo.data/...`, and shared data s The default no-name app, via `/script run` command can only save/load/read files from the shared space. -Functions return `null` if an error is encounter or no file is present (for read and delete operations). Returns `true` -for success writes and deletes, and requested data, based on the file type, for read operations. - -NBT files can be written once as they an store one tag at a time. Consecutive writes will overwrite previous data. - -Write operations to text files always result in appending to the existing file, so consecutive writes will increase -the size of the file and add data to it. Since files are closed after each write, sending multiple lines of data to -write is beneficial for writing speed. To send multiple packs of data, either provide them flat or as a list in the -third argument. - * `write_file('temp', 'text', 'foo', 'bar', 'baz')` or - * write_file('temp', 'text', l('foo', 'bar', 'baz')) +Functions return `null` if an error is encounter or no file is present (for read, list and delete operations). Returns `true` +for success writes and deletes, and requested data, based on the file type, for read operations. It returns list of files +for folder listing. -To log a single line of string - -Supported values for resource `type` is: +Supported values for resource `type` are: * `nbt` - NBT tag * `text` - text resource with automatic newlines added * `raw` - text resource without implied newlines - * `shared_nbt`, `shared_text`, `shared_raw` - shared versions of the above + * `folder` - for `list_files` only - indicting folder listing instead of files + * `shared_nbt`, `shared_text`, `shared_raw`, `shared_folder` - shared versions of the above NBT files have extension `.nbt`, store one NBT tag, and return a NBT type value. Text files have `.txt` extension, stores multiple lines of text and returns lists of all lines from the file. With `write_file`, multiple lines can be sent to the file at once. The only difference between `raw` and `text` types are automatic newlines added after each -record to the file. +record to the file. Since files are closed after each write, sending multiple lines of data to +write is beneficial for writing speed. To send multiple packs of data, either provide them flat or as a list in the +third argument.
-write_file('foo', 'shared_text, l('one', 'two'));
+write_file('foo', 'shared_text, ['one', 'two']);
 write_file('foo', 'shared_text', 'three\n', 'four\n');
 write_file('foo', 'shared_raw', 'five\n', 'six\n');