Skript

Skript

743k Downloads

Add dependencies section to skripts

Palgia opened this issue ยท 3 comments

commented

Suggestion

It would be so useful to be able to define a Skript as dependent on another so that it is ALWAYS loaded after its dependencies, no matter its position in the directory tree.

I know that by organizing the directory tree, one can define the order in which scripts are loaded, but it would be very, very useful for servers that use a lot of scripts, or for those who share their resources on SkUnity, etc. Because everyone manages their directory tree as they wish according to their needs, and I think we should be able to define a mandatory loading order in the configuration of Skript.

We could add a new section in the scripts, like "dependencies," which allows Skript to understand that this script must be put in a waiting list until the other scripts on which it depends are not loaded.

This could also be used with plugins, to load scripts after a plugin is loaded because there's a lot of issues when using externals API with skript-reflect (for example, ItemsAdder always loads after Skript which causes many issues).

This system could work in the following way:

  • Skript loads all scripts without fully reading them. It first detects the 'dependencies' sections, which must be placed at the top of the script.
  • Then Skript organizes an ordered list of all scripts based on their dependencies and loads them.

An option should be added in config.sk to enable or disable this, such as 'enable-dependencies'. If this is disabled, the classic method of Skript would be retained, which would allow those who do not need this type of loading not to use it, as it could potentially be longer.

Why?

Useful for servers that manage many scripts, or for those who share their resources which depend on other resources.

Other

Example:

dependencies:
    scripts:
        # Checks if a skript named MySkript.sk exists, to load this skript after it
        - "MySkript.sk"
    plugins:
        # Checks if the plugin 'ItemsAdder' exists to load this skript after it
        - ItemsAdder

Agreement

  • I have read the guidelines above and affirm I am following them with this suggestion.
commented

This can some how be done with SecConditional parse if section specifically.

parse if plugin "AyhamSk" is not enabled then disable the script/stop loading specific parts

commented

It works as a workaround, I use this myself. But if the skript you set in the condition is not loaded before your script, it is useless.
As I said before, I know we can define the loading order by ordering the skripts.

But it becomes messy when there are a lot of scripts, or when you share resources on SkUnity, because everyone has its own way to organize its scripts.

Setting dependencies could solve everything.

commented

This shouldn't be necessary. We have put a lot of effort into trying to make forward references safe (e.g. using functions from another script shouldn't be conditional on load order). I'm assuming you're requesting this because of an addon that doesn't allow this kind of reference. If there's something breaking this then it's probably better to fix that than to add some kind of work-around system.

It's very hard to make script->script dependencies work in practice. In theory we just have to delay parsing it until last, but in practice that's not actually going to help.

If I have two scripts declaring dependencies which do I attempt parsing first? What if they declare a dependency on each other? What if they ask for a script but there's more than one script with that name? What if a user downloads your script and renames it?

Dependencies work (ish) with plugins because they're packaged and deployed in a non-editable resource format, so they can be very confident that things will be as they expect them to be. A script is a glorified text file that's designed to be edited, so there's absolutely no safety assurance.
If we make this, it will probably be very unreliable and not fix the problems that you want it to.