Skip to content

Resource

const resource = require("@vectarine/resource")

Functions common to all resources

A resource is an external piece of data. Use the loader module to load resources. You shouldn’t need to import this module.

export type Resource = ...
Resource:getStatus(): string | "NotLoaded" | "Loading" | "Loaded"

Get the status of a resource.

When loadResource is called, the resource is created in an Unloaded state. Once per frame, "Unloaded" resources are scheduled for loading, and their state becomes "Loading". When the loading is finished, the state becomes "Loaded" or "Error: Description of the error" if something went wrong. When a resource which is not "Loaded" is used, nothing will happen and a warning will be printed in the console.

Resource:isReady(): boolean

Check if a resource is ready to be used. This is the same as checking if getResourceStatus returns "Loaded".

Resource:getId(): number

Get the ID of a resource. The ID is a number that is unique to the resource. The ID stays constant between reloads (but not restarts!)

Returns number

export type ScriptResource = ...
export type TextResource = ...
TextResource:getText(): string?

Get the text of a text resource. Or nil if the resource is not loaded or does not exist.

Returns string?