Pixel Vision OS includes a special folder that allows you to share commonly used code across projects. This folder is located in the
When Pixel Vision OS loads up a game, it scans the
/System/Libs/ directory and makes all of the scripts available to load at runtime via the
LoadScript() API. There is a specific order to how shared libs are loaded based on where Pixel Vision OS finds them. Here is the priority order.
The root of the game folder
The lower the priority number, the more important it will be. For example, if you have a script called
utils.lua in the workspace folder you could load it by calling the following at the top of your game’s
Notice that you don’t need the file extension or the full path to the file. Each Lua file is indexed by its filename only so it is easier to reference at runtime. Now, if you also have a disk with a
/System/Libs/ folder that includes a
utils.lua file, that will overwrite the one located in the
/Workspace/System/Libs/ directory. Finally, if you have a
utils.lua file in the root of your game directory, that will overwrite the one located on the disk and/or the Workspace.
It’s important to give shared library files unique names to avoid conflicts. You can put any Lua file you want to share between your games in the
/Workspace/System/Libs/ directory. This is a perfect place to share commonly used code logic between games to help speed up your development.
The one thing to keep in mind is that when you build your game and create a .pv8 disk, it will not include any shared library files. If you are using a lot of shared files between games, simply copy them over to your final game project before performing a build or use the Pro Tool’s Build Tool which offers you an option to include shared libs in your final build.
Since shared library files do not require a path, just the filename, adding them to the final build of the game doesn’t require any code changes. All you need to do is include the dependant files in the final build and everything will load as expected.