Dedicated storage for library code
djmattyg007 opened this issue ยท 9 comments
I've written a bunch of common "library" code that I'd like to share between computers. Is there an easy way to do this? Right now I have to manually copy it between computers, and then I have to manually keep it up to date too.
Even if there was no way to share it between computers, it would still be ideal if there was a dedicated path within each computer for storing this code that was automatically added to package.path
. Right now I store it in the root folder of each computer, and add this to the top of every script:
package.path = "/?;/?.lua;/?/init.lua;" .. package.path
Would you be able to expand on that? How does it work? How would I learn to do that? What makes that solution exclusive to single player?
https://github.com/cc-tweaked/datapack-example. The readme explains pretty much all of the how-to. It's not exclusive to single player per se, it's just that you need admin access to the multiplayer server in order to make it load a pack, which isn't always an option. Also the datapack content will affect all computers, which may not always be a great idea in multiplayer.
In-game solution could be to store this library on a disk, and connect every computer to the same disk drive (wired network). Put a startup on the disk which load the library. Then you can use this library on every computers, from a single file.
I don't mind the datapack idea too much, but it isn't very dynamic. Every change would require reloading configuration in full.
Who needs storage?! ๐
Alternative approach: If HTTP is allowed, you could make use of http.get
+load
+pcall
Lua functions to dynamically run Lua code from pastebin or GitHub repo/gist or whatever ๐
This has several benefits, as you can just update the file remotely by using git (in case you're using github repo/gist), or just use web UI in case you're not familiar with git.
Here goes a live example:
- Download/copy/save the
runlib
script to your CC computer, you can also usewget
command. - Open terminal and enter
runlib Cheatoid:printf
, this would download and import the library into Lua environment. - Now you can call a brand new
printf
function in your Lua scripts. You can also userunlib("libraryId")
from within Lua. - By utilizing
startup
script, you can take this further. It is also possible to make a system which automatically updates libraries on all target computers, etc.