Skip to main content

require

In Simulo, we have the global require function. It's available in components and the script box, but NOT directly in tools. To use it in tools, you'll need RemoteScene:run.

require is what you use to import things like:

  • Lua variables or functions
  • Assets (images, audio, etc.)
  • Components

It can only load things in your Simulo folder. You can either use a relative path (like ./packages/@user/package/...), or a package path (like @user/package/...). You can use either, the only difference is the latter is shorter and cleaner.

-- You can use a package path like @user/package/... to import
local image = require('@joe/stuff/assets/image.png'); -- resolves to ./packages/@joe/...

-- Or you can use a path relative to the Simulo folder directly:
local audio = require('./objects/my_object/scream.wav');

local texture = require('core/assets/textures/point_light.png');

local some_value = require('./some_script.lua'); -- it runs the script. anything that isn't `local` is now in our here. whatever that script returns is the return value of the `require`

Lastly, you can pass a second parameter, to force it to load the thing in a certain type. By default, it'll guess based on the file extension. But we can do this:

local code = require('./packages/core/attachments/camera/attachment.lua', 'string');

That forces the Lua to load as a string, instead of running it. Wow! You can also set to texture, lua, audio, component fr.