Skip to content

sagl.files

The server's client files: already on the player's computer before scripts run.


sagl.files.read(path)

sagl.files.read(path: string): string | null

Reads a client file as text.

Parameter Type Description
path string The client file's path, e.g. "data/shops.json".

Returns its contents, or null if there's no such file.

const shops = JSON.parse(sagl.files.read("data/shops.json") ?? "[]");
for (const s of shops) sagl.map.setMarker(s.id, { x: s.x, y: s.y, icon: s.icon, label: s.name });

sagl.files.url(path)

sagl.files.url(path: string): string | null

Where RML finds a client file, for src and href in any document or page.

Parameter Type Description
path string The client file's path.

Returns the URL, or null for an invalid path.

page.setHtml("icon", `<img src="${sagl.files.url("ui/icons/pistol.png")}" width="32dp" height="32dp"/>`);

In RML

A document opened with sagl.ui.openFile links other client files relatively, and SAGL's theme absolutely:

<link type="text/rcss" href="/sagl/ui/theme/base.rcss"/>
<link type="text/rcss" href="shop.rcss"/>
<img src="icons/pistol.png"/>

RmlUi only reads SAGL's sagl/ui/ and the current server's client files.