Forums » Community Projects
scriptmanager
I threw a little scriptmanager together today.
available here:
http://home.arcor.de/famscheffler/ven/sm.lua
It's not terribly awesome mostly because of some limitations in the api but it may make handling many scripts a bit easier with a "friendly" gui instead of having to edit text files.
It basically just allows you to set a path where to look for scripts and create a list of scripts to run from there when the manager is run.
to use it save the scriptmanager script in the game directory and run it with /lua dofile("sm.lua") fire up the gui with /lua sm()
Now to run for example the scripts test.lua and radar.lua from the directory "scripts" set "scripts dir" to "scripts/" (or "scripts\" on windows). and add "test" and "radar" to the list.
now everytime the scriptmanager is run (with /lua dofile("sm.lua")) it will run those scripts as well.
I'd love to automate the loading of scripts a bit more like an "run every script from this directory" option and stuff.. but without any io that's tricky :P
A kind of script registry would be nifty. That could be as simple as creating an entry in a predefined format in a table. The scripts to be loaded would have to take care of registering themselves. It'd allow for quite a few features to be added to mine or other script managers.
Registration could look something like this:
ScriptRegistry.<nameofscript> =
{
autorun=<is this script supposed to be run my the sm>
filename=<filename of script>
desc=<description of script>
initfunc=<function to initialize>,
resetfunc=<function to reset script>
configfunc=<function that pops up config dialog>
guifunc=<pops up gui of the script>
stopfunc=<suspends script>
.
.
.
}
most of the fields would be optional.
if a new script is loaded the manager could then go "hey! a new script!" and automatically add the script to its list and provide a gui to control it.
available here:
http://home.arcor.de/famscheffler/ven/sm.lua
It's not terribly awesome mostly because of some limitations in the api but it may make handling many scripts a bit easier with a "friendly" gui instead of having to edit text files.
It basically just allows you to set a path where to look for scripts and create a list of scripts to run from there when the manager is run.
to use it save the scriptmanager script in the game directory and run it with /lua dofile("sm.lua") fire up the gui with /lua sm()
Now to run for example the scripts test.lua and radar.lua from the directory "scripts" set "scripts dir" to "scripts/" (or "scripts\" on windows). and add "test" and "radar" to the list.
now everytime the scriptmanager is run (with /lua dofile("sm.lua")) it will run those scripts as well.
I'd love to automate the loading of scripts a bit more like an "run every script from this directory" option and stuff.. but without any io that's tricky :P
A kind of script registry would be nifty. That could be as simple as creating an entry in a predefined format in a table. The scripts to be loaded would have to take care of registering themselves. It'd allow for quite a few features to be added to mine or other script managers.
Registration could look something like this:
ScriptRegistry.<nameofscript> =
{
autorun=<is this script supposed to be run my the sm>
filename=<filename of script>
desc=<description of script>
initfunc=<function to initialize>,
resetfunc=<function to reset script>
configfunc=<function that pops up config dialog>
guifunc=<pops up gui of the script>
stopfunc=<suspends script>
.
.
.
}
most of the fields would be optional.
if a new script is loaded the manager could then go "hey! a new script!" and automatically add the script to its list and provide a gui to control it.
We could agree on a standard area to write to the config.ini script files, which would then be used by script managers such as your own. I'm thinking a [Scripts] header with, firstly, a scripts="blah" entry, where blah is a spickled table indicating the files that need to be loaded for each script.
More visually, I think it would look like so in the config.ini:
(Windows recognizes either \scripts\ or /scripts/, by the way)
[Scripts]
scripts="test","MakeFriends","loadrep"
test="scripts/test.lua"
MakeFriends="scripts/radar.lua"
loadrep="scripts/loadrep.lua"
Scripts should handle loading their own files if they require multifile support, to keep the config.ini from being crowded up. Namely, this is bad:
[Scripts]
scripts="test","MakeFriends","loadrep"
test="_testfuncs","_testgui"
_testfuncs="scripts/test/testfuncs.lua"
_testgui="scripts/test/testgui.lua"
MakeFriends="_MakeFriends"
_MakeFriends ="scripts/radar.lua"
loadrep="_loadrep"
_loadrep="scripts/loadrep.lua"
This is bad for two reasons. First, it clutters the config.ini. Sure under one header, but still ugh. Second, and more important, it makes it harder to remove scripts because you need to remove each of the files they use.
Now, something that might be neat is a way to specify dependencies so that scriptmanagers don't load scripts until all their dependencies are loaded. Taking the good example from above:
[Scripts]
scripts="test","MakeFriends","loadrep"
test="scripts/test.lua"
test_depends="MakeFriends"
MakeFriends="scripts/radar.lua"
loadrep="scripts/loadrep.lua"
loadrep_depends="test"
In this case, MakeFriends would be loaded first(no dependencies field. Default for ReadString should be ""), then test, then loadrep.
I'll be damned if I'm writing a script manager though, ugh.
More visually, I think it would look like so in the config.ini:
(Windows recognizes either \scripts\ or /scripts/, by the way)
[Scripts]
scripts="test","MakeFriends","loadrep"
test="scripts/test.lua"
MakeFriends="scripts/radar.lua"
loadrep="scripts/loadrep.lua"
Scripts should handle loading their own files if they require multifile support, to keep the config.ini from being crowded up. Namely, this is bad:
[Scripts]
scripts="test","MakeFriends","loadrep"
test="_testfuncs","_testgui"
_testfuncs="scripts/test/testfuncs.lua"
_testgui="scripts/test/testgui.lua"
MakeFriends="_MakeFriends"
_MakeFriends ="scripts/radar.lua"
loadrep="_loadrep"
_loadrep="scripts/loadrep.lua"
This is bad for two reasons. First, it clutters the config.ini. Sure under one header, but still ugh. Second, and more important, it makes it harder to remove scripts because you need to remove each of the files they use.
Now, something that might be neat is a way to specify dependencies so that scriptmanagers don't load scripts until all their dependencies are loaded. Taking the good example from above:
[Scripts]
scripts="test","MakeFriends","loadrep"
test="scripts/test.lua"
test_depends="MakeFriends"
MakeFriends="scripts/radar.lua"
loadrep="scripts/loadrep.lua"
loadrep_depends="test"
In this case, MakeFriends would be loaded first(no dependencies field. Default for ReadString should be ""), then test, then loadrep.
I'll be damned if I'm writing a script manager though, ugh.
I think the script manager should run outside VO, and be a separate program, or even better -- it should be in VOKB client (as we already have to run VOKB client to use its features). It should take care of installing and updating the addons (as package managers in Linux do) and creating "startup" script (which would contain dofile's for every installed script)
I personally don't like external programs(one reasons why I don't use vokb), and thusly, would not like to see the only script manager being stuck in vokb or some external program. I'd end up having to write an ingame lua scriptmanager using the config.ini as above just out of spite :/
meh. doing it via the config file sounds needlessly awkward.
I'm not sure if you can store functions in it either, which is trivial with an ingame table and would be my primary interest so that the scriptmanager has some control over scripts, scripts could like stop all other scripts while they do their thing and stuff like that.
Dependency handling should be IMO done by the scripts themselves, although the registry could streamline that.
The script could just check if the entry of the dependency in the registry and load it if not... or in code:
if not ScriptRegistry["dependency"] then dofile("dependency") end
The whole registry thing is just something I thought up while writing the post anyway .. I don't claim that the idea is thoroughly thought through.
I'm not sure if you can store functions in it either, which is trivial with an ingame table and would be my primary interest so that the scriptmanager has some control over scripts, scripts could like stop all other scripts while they do their thing and stuff like that.
Dependency handling should be IMO done by the scripts themselves, although the registry could streamline that.
The script could just check if the entry of the dependency in the registry and load it if not... or in code:
if not ScriptRegistry["dependency"] then dofile("dependency") end
The whole registry thing is just something I thought up while writing the post anyway .. I don't claim that the idea is thoroughly thought through.