Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing code with lua. Require("") #2460

Open
mythrz opened this issue Aug 6, 2023 · 0 comments
Open

Reusing code with lua. Require("") #2460

mythrz opened this issue Aug 6, 2023 · 0 comments
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.

Comments

@mythrz
Copy link
Contributor

mythrz commented Aug 6, 2023

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.

@ShaunaGordon ShaunaGordon added kind/bug Categorizes issue or PR as related to a bug. good-first-issue Issue ready for a new contributor according to the help wanted guidelines. feature/scripting This item is related to the scripting tools. labels Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants