Reusing code with lua. Require("") #2460
Labels
feature/scripting
This item is related to the scripting tools.
good-first-issue
Issue ready for a new contributor according to the help wanted guidelines.
kind/bug
Categorizes issue or PR as related to a bug.
https://github.com/o3de/o3de.org/blob/12279652861ad4ddedfbfaac3f43d3e931e48d1d/content/docs/user-guide/scripting/lua/environment.md?plain=1#L17C322-L17C366
"The file path is delimited by periods instead of slashes, has no .lua file name extension, and is relative to the O3DE assets directory."
In my machine, it is relative to the project folder. The root folder of my custom O3DE project, NOT the assets folder.
So If my script is inside the Assets folder, it would be something like this:
local library = require("Assets.Scripts.MyLibraryFile")
Also, the period is not the only way to require scripts, you can also use double slashes, like so:
local library = require("Assets\\Scripts\\MyLibraryFile")
This is important to know because whenever you want to reference other extensions (.json or .uicanvas) you should use its extension so a warning does not appear, saying it auto-appends the extension. If you were to use only periods, you would have no way to mute the warning.
The text was updated successfully, but these errors were encountered: