Loader
const loader = require("@vectarine/loader")Loader
Functions to load external resources like images, scripts, fonts, shaders, audio, etc.
Functions
Section titled “Functions”loader.loadScript
Section titled “loader.loadScript”loader.loadScript<T>(path: string, type_hint: T?): (Res.ScriptResource, T)Similar to require(), but it is synchronous and will return an empty table if the script has not been loaded yet. Usually, you should use require() unless you want to load your scripts asynchronously, if you have a lot of scripts.
For typing purposes, you can pass a table as the second argument, but this has no runtime effect. The return value is a ScriptResource and the module table returned by the script.
Example:
local loader = require("@vectarine/loader")-- We pass require("other.luau") as the second argument to get proper type inference for the returned module "other".local res, other = loader.loadScript("scripts/other.luau", require("other.luau"))Parameters
path(string): For example scripts/monster.luatype_hint(T?): A table to hint the type of the module returned by the script. This has no runtime effect.
loader.loadImage
Section titled “loader.loadImage”loader.loadImage(path: string, antialiasing: boolean?): Image.ImageResourceLoad an image from a path If antialiasing is true, the image will be drawn with linear filtering, otherwise with nearest filtering. If you are using a pixel art style, you probably want antialiasing to be false.
Parameters
path(string): string
Returns ImageResource
loader.loadFont
Section titled “loader.loadFont”loader.loadFont(path: string): Text.FontResourceLoad a font from a path
Parameters
path(string): string
Returns FontResource
loader.loadText
Section titled “loader.loadText”loader.loadText(path: string): Res.TextResourceLoad text from a path. The path should be relative to the game.vecta file, like “./texts/mytext.txt”
Parameters
path(string): string
Returns TextResource
loader.loadShader
Section titled “loader.loadShader”loader.loadShader(path: string): Canvas.ShaderResourceLoad a shader from a path
Parameters
path(string): string
Returns ShaderResource
loader.loadAudio
Section titled “loader.loadAudio”loader.loadAudio(path: string): Audio.AudioResourceLoad audio from a path
Parameters
path(string): string
Returns AudioResource
loader.loadTileset
Section titled “loader.loadTileset”loader.loadTileset(path: string): Tile.TilesetResourceLoad a tileset from a path
Parameters
path(string): string
Returns TilesetResource
loader.loadTilemap
Section titled “loader.loadTilemap”loader.loadTilemap(path: string): Tile.TilemapResourceLoad a tilemap from a path
Parameters
path(string): string
Returns TilemapResource
loader.init
Section titled “loader.init”loader.init(): nilReturn a table which is referentially stable across script reloads for a given script, or nil if the script has never been loaded before. You should use this table to store the functions and properties declared in your script.
local loader = require("@vectarine/loader")local module = loader.init() or {}if not module.hasBeenLoaded then --- This module has been loaded for the first time!end--- Define all the properties of your module heremodule.hasBeenLoaded = truereturn module