File Actions
os.download(data: (string | object | ArrayBuffer | Blob), filename: string, mimeType: string): DownloadAction
Downloads the given data with the given filename and MIME Type.
The first parameter is a (string | object | ArrayBuffer | Blob) and is the data that should be downloaded. This can be a string, object, or binary data in the form of an ArrayBuffer or Blob .
The second parameter is a string and is the name of the file that should be downloaded.
The third parameter is a string and is the MIME Type that the downloaded file should have. If not provided, then it will be inferred from the provided filename.
Examples
Download a text file named "test.txt" that contains "abc".os.download("abc", "test.txt");
os.downloadBots(bots: Bot[], filename: string): DownloadAction
Downloads the given array of bots as a
.aux
or a.pdf
file with the given filename. Useful for quickly backing up a set of bots.The downloaded bots will be stored in the Version 1 format of the AUX File Format, which is well suited for most scenarios. For scenarios where you want conflict-free initialization of a shared inst, you should use
os.downloadBotsAsInitialzationUpdate(bots, filename)
.The first parameter is a Bot[] and is the array of bots that should be downloaded.
The second parameter is a string and is the name of the file that the bots should be stored in. If the filename ends with
.pdf
, then a PDF file will be downloaded with the bots as embedded data. Otherwise,.aux
will automatically be added to the end of the filename.Examples
Download all the bots in the "abc" dimension as "abcBots.aux".os.downloadBots(getBots(inDimension("abc")), "abcBots");
Download the current bot as "currentBot.aux".os.downloadBots([bot], "currentBot");
Download all bots as "myServer.pdf".os.downloadBots(getBots(), "myServer.pdf");
os.downloadBotsAsInitialzationUpdate(bots: Bot[], filename: string): DownloadAction
Downloads the given array of bots as a
.aux
or a.pdf
file with the given filename.The downloaded bots will be stored in the Version 2 format of the AUX File Format, which is better suited towards scenarios which require conflict-free initialization of a shared inst from the AUX file. For an archive of the current state, you should use
os.downloadBots(bots, filename)
which is better for scenarios which require direct access to the bot data.The first parameter is a Bot[] and is the array of bots that should be downloaded.
The second parameter is a string and is the name of the file that the bots should be stored in. If the filename ends with
.pdf
, then a PDF file will be downloaded with the bots as embedded data. Otherwise,.aux
will automatically be added to the end of the filename.Examples
Download all the bots in the "abc" dimension as "abcBots.aux".os.downloadBotsAsInitialzationUpdate(getBots(inDimension("abc")), "abcBots");
Download the current bot as "currentBot.aux".os.downloadBotsAsInitialzationUpdate([bot], "currentBot");
Download all bots as "myServer.pdf".os.downloadBotsAsInitialzationUpdate(getBots(), "myServer.pdf");
os.downloadInst(): DownloadAction
Downloads all of the shared bots into a
.aux
file on the player's computer. The file will have the same name as the inst.Note that this function is almost exactly the same as
os.downloadBots(bots, filename)
. The only difference is that all bots in the shared space are included and the file is named for you automatically.Examples
Download the entire inst.os.downloadInst();
os.parseBotsFromData(jsonOrPdf: (string | ArrayBuffer)): Bot[]
Parses a list of bot mods from the given string of data. The data can be JSON or the contents of a PDF file. Returns an array of mods where each mod has the structure of a bot (i.e. it has
id
andtags
properties). Returnsnull
if the data is not valid JSON or PDF.The first parameter is a (string | ArrayBuffer) and is the JSON data or the contents of the PDF file that should parsed.
Examples
Parse the list of bots in an @onFileUploadlet bots = os.parseBotsFromData(that.file.data);
os.importAUX(urlOrJSON: string): Promise<void>
Imports an AUX file from the given string.
If the string contains JSON, then the JSON will be imported as if it was a .aux file. If the string is a URL, then it will be downloaded and imported.
This is useful to quickly download a AUX file and load it into the current inst from a site such as https://gist.github.com/.
The first parameter is a string and is the URL or JSON to load. If given JSON, then it will be imported as if it was a
.aux
file. If given a URL, then it will be downloaded and then imported.Examples
Import an AUX file from a file.const path = '/drives/myFile.aux';
os.importAUX(path);Import an AUX file from JSON.os.importAUX(`{
"version": 1,
"state": {
"079847e4-6a58-423d-9a86-8d4ef8be5970": {
"id": "079847e4-6a58-423d-9a86-8d4ef8be5970",
"tags": {
"color": "red"
}
}
}
}`);os.showUploadAuxFile(): ShowUploadAuxFileAction
Shows the "Upload AUX File" dialog which lets the user select a .aux file to upload to the inst.
Examples
Show the "Upload AUX File" dialog.os.showUploadAuxFile();
os.showUploadFiles(): Promise<UploadedFile[]>
Shows the "Upload Files" dialog which lets the user select some files to upload to the inst. Returns a promise that resolves with the list of files that were uploaded.
Examples
Show the "Upload Files" dialog.const files = await os.showUploadFiles();
os.toast("You uploaded " + files.length + " file(s)!");