IMPORTANT
Ly Require and all the Ly Libraries uses a feature of lua that is not supported by Crayta as a way to pass libs around. While this will get fixed you could use X1 as alternative to LyRequire, still there are no plans to make Ly libraries compatible with X1 in the near future as I hope that Crayta will get a native library solution that doesn’t imply the use of _G.
Ly Require is the glue of Ly Framework and is a dependency for every other package.
It let’s you get other libraryes from the Ly global table.
the package contains a script folder template LyFramework_AddToFirstWorldEntity that should be added to one of the first entities added to the world (preferibly the first one).
Ly libraries get initializated during the init function of the entity you attach the folder to.
If an entity need to access Ly libraries in it’s init it’s entity should be added to the world later than ther one with the LyFrameworkFolder or its init will be called before Ly Framework get initialized.
To be 100% safe I create a new world , remove all entities from it and add a locator called Game at 0,0,0 with the Ly Framework Folder.
your libraries should be added to lib subfolder and should implement at least LyRegister(Ly)
LyRequire Calls 2 functions to all scripts in the installation entity.
LyReguster(Ly)
Gives you the opportunity to add your library tables to the Global Ly object
function script:LyRegister(Ly)
-- it passes you the Ly table add your library table to it.
Ly.Array = Array -- for example I added my array library to Ly.Array
here you can also init your library if it doesn't need any other Ly libraries dependencies.
end
LyResolve(Ly)
Called after all LyRegister(Ly) functions but before every other entity Init is called.
Here you can setup your dependencies and init your library that requires dependencies to work.
function script:LyResolve(Ly)
-- it passes you the Ly table add your library table to it.
Mylib.Init(Ly.Array) -- for example here I passed Ly.Array to my library's init function so that it could be used in my lib
end
Please refer to my libraries for an example of how a lib can be implemented and used in other scripts.
IMPORTANT Lib Development
To develop libs in Crayta you need to know a workflow to update libs with no issues due to global Ly object not updating and getting stale.
Put entity with Ly Framework Folder to simulation and remove and readd LyRequire every time you save changes to any library in subfolders so that the global table will get updated with your changes and don’t still refer to previous version of the Library.