External Scripts Framework

This script is in dire need of some detailed and extensive documentation, so I'll be working on that soon. In the meantime, if you're interested in seeing how it can be used in a "real world" project, you can take a look at this demo for my Ease Script: This is a download for the demo shown in the video

What you'll see in the root of the plugins directory (Data/Plugins) is a scripts.rb file; this file is automatically generated each time you test the game. It contains all the scripts in the correct order specified by the bootstrap files in each plugin folder. The reason it's generated is that encrypted archives do not allow for importing script files from sub-folders during runtime (there is no method available to traverse folders in an encrypted game), so instead I just import that one file, making the framework work for encrypted archives as well as having no overhead when loading the script files, as it only needs to load one file and evaluate that. I'll be providing a much more comprehensive explanation of this when I update the framework with full documentation and some new "quality of life" features.
  1. Yes, you can replace default RM scripts with it, just like in the editor. For a "real world" example, you can check out the demo project for my easing script; it utilizes this plugin system to both provide completely new methods and classes, and extending Ace's Game_Picture class and other classes. It shows off the kind of folder structure you can use, too.
  2. One way to disable scripts right now is to comment out Plugins.load_files within bootstrap.rb files in subfolders, but that will exclude all the files in that subfolder. This is actually something I've wanted myself (a way to exclude certain scripts easily for debugging or testing), so I'm going to add this feature ASAP. I'll give you a heads up once it's done.
  3. It does support encryption. The way I set it up, it works like this: Upon testing your game, it rebuilds scripts.rb, a file where all the scripts are added in the correct sequence. All contents of /Data in RM projects get encrypted, but in encrypted mode, we no longer have access to the file finding and searching methods I use when building this file, so I then make the Plugin manager skip rebuilding scripts.rb and just go ahead and load it. Since you can tell it to load scripts with absolute paths in encrypted mode, this works fine. This means that in an encrypted game, your scripts are protected just like they are when entered into the built-in editor 🙂
The Plugin Framework scripts suffer a bit from lack of good documentation; while the code itself is relatively well documented, it's not exactly user friendly documentation. Since there's interest for it (and not just me using it), I'm going to take some time and write proper documentation for this as soon as I can. A plan I had for this all along was to make a very simple GUI application with drag and drop, to let people manage their scripts easily using this framework, but without needing to write anything. While this works very well for my current use, I find myself sometimes wishing it was even easier to manage my scripts; lazyness is the greatest of motivators 😉 After the IGMC, that script manager GUI will be my new project.

In the meantime, feel free to ask me any questions you might have in the thread, and I'll make sure to reply in a timely manner.
1. Sorry I actually meant to replace the entire script (to not load the original one into memory at all). Not just extending. My mistake. Your script works as well by disabling it. I forgot to disable the script that had the raise 'something'...

2. That won't do because dependencies will stretch across folders for me for sure. If you would add that feature then your script would be a really good option for me.

I couldn't find a license for it (sorry if I missed it). Free to use for non- and commercial use with credit given by any chance?
  1. I'm not entirely sure I understand; you can extend or overwrite RM's default scripts (or any other scripts) in the same manner as in RM's script editor. As long as a script file is loaded after whatever it should overwrite or extend, of course 🙂
  2. I'll definitely add that; I'll try to do it later today, as it's a really small job.
License is indeed free for commercial and non-commercial use with credit given. I updated the first post with this information: You should credit Tsukihime (her license is compatible, and I use her External Script Loader script) and Galenmereth 🙂
About #1

If I extend or overwrite a script that has already been loaded by Ace then some scripts may already have been executed. Some scripts may have code that is executed directly.

If I create a new script and only add this line:

raise 'test'Then overwriting or extending it to prevent it from raising that won't work because RM already crashed on that line when loading that script. I tested it.

But even if I do it through a class the 2nd script won't overwrite the first script in time. Therefor disabling such scripts won't work with your system.

Code:
# Script 1, loaded firstclass Foo  def initialize	raise 'f'  endenda = Foo.new# Script 2, loaded 2ndclass Foo  def initialize	puts "no crash"  endend# Result: your system will crash on script 1 because the overwrite is too late.
This is correct, but the problem would similarly arise in the built-in editor; if a script executes a method before a second script gets a chance to overwrite that method, then you'll get the same problem. Scripts should never do this, however, because it makes them incompatible with extensions and modifications, and most other scripts 🙂

If you're encountering this because you want to try out the plugin framework without emptying the built-in editor of scripts (meaning you have duplicates of scripts that need to execute methods like mentioned above), I'd recommend making a copy of the project in its entirety, then test the plugin framework without any scripts in the built-in editor (other than the two necessary entries to load the plugin framework).
Not really. My script doesn't have that problem in the build-in editor. It prevents such code as well.

It may indeed not be proper coding but I have a few scripts that do that 🙁 .
I tested that in a blank project (using the built-in editor), and it does raise "f" as it should, so I'm a bit uncertain what makes that work on your end 🙂 The built in editor works basically the same as my script plugin, in that every entry gets eval'd in sequence, so there shouldn't be a difference as long as the order is set correctly.
I made a mistake when I used your demo. It works fine regarding #1.

1. Sorry I actually meant to replace the entire script (to not load the original one into memory at all). Not just extending. My mistake. Your script works as well by disabling it. I forgot to disable the script that had the raise 'something'...
That is good to hear! You'll be pleased to know that I've updated the demo file linked in the first post, and implemented changes to the Plugins module:

  • A new option is now available when using Plugins.load_files, called :exclude. Use it to provide an array of files you wish to exclude from being loaded.
  • A new way to define folder structures that does not require bootstrap.rb files has been included, and is called Plugins.load_recursive. It requires a hash structure. Please look at the demo project, as it has been updated with this new solution. The old bootstrap.rb based loading is still there for backwards compatibility, but the new load_recursive method should be preferred as it requires far less typing overall, and is much easier to control 🙂
As mentioned above, the demo project file has been updated, and you can take a look at it to see how the new solution works. The new features have been commented.
I hope it's ok to bump this, as I've bumped the minor version with a very useful new feature for the order array option.

One thing that started annoying me lately, and which I resorted to some really weird workarounds to achieve, was this: What if I want to order some scripts first, then some scripts last, and have the rest included alphabetically (default) in between? For example, a few scripts must be after all others that affect the same things it does. Well, I implemented a feature for that! Here's an excerpt from the demo setup file:

plugins = { - removed for brevity -, "Example 2" => { order: [ # If you specify an order array for a folder, those files will be loaded first "data", :rest, # If you insert the symbol :rest into the order array, all files not mentioned # in the order array will be inserted between here and the remaining order items. # This means that you can easily sort some scripts before and after all the rest. "insert last" ] }, - removed for brevity-}So the script file "data" will be loaded first, "insert last" at the end, and all the other files alphabetically (as in the folder structure) in between. This should come in handy.Another thing I'd like to mention is how you can use the exclude parameter array intelligently. What if you want to exclude a lot of scripts but only when you go into "production" (that is, when you export a game for players, and not for testing)? Here's one way to solve that quite elegantly, and also how to use :rest in real-life scenarios. By using one boolean option (production) I can make sure that scripts such as shaz' passage modding scripts–which are only required for testing–are excluded when I set the production variable to true.

rest_and_smart_exclude.PNG


Keep in mind that you will still need to run the game once in Ace test mode to rebuild the script file. I hope this comes in handy for those that might be using the Plugin Framework 🙂
What about using the $TEST variable that is set when you playtest? Then you wouldn't have to manually set it to true/false.
What changes $TEST from true to false though? Does that happen when you use the Compress option? Does that also recompile all the scripts and would it exclude those?
It's a command-line argument that is passed to the exe, which is uses to determine whether it should be set to true or false.
The problem with using $TEST is that it is available during runtime/startup, but due to the way encrypted executables work, it won't work with the current Plugin Framework implementation. Since we cannot recompile the scripts.rb file in an encrypted environment, we use the one that was last generated in test mode using an absolute path. Things like recursively searching folders for files does not work in encrypted mode, but absolute paths do. This is the reason I can't just load all the scripts directly.

There are ways to implement it that I can think of, but I'm not sure it's a good idea. Since the $TEST variable will only be false when you run the game in "production" mode, it will also make it harder for you as a developer to test if all the exclusions are correct. What if you've accidentally excluded a script you didn't mean to, for example, but some output in the console might help you notice this? This is why I think it's worth the extra effort to set a variable manually, test and see if all is good, and then compress/export your game 🙂

One solution I'm looking to implement instead of compiling all the scripts into the scripts.rb file, is to instead compile an array or hash (with options) list of all absolute paths to the scripts that are to be included, and then use load_script to load each of them individually during start up. This will decrease filesize somewhat, since we won't need a copy of all the scripts in the scripts.rb file, but there are scenarios where this might not be preferrable. For instance, if you use the Plugin Framework to put together a script file for public use, like I've done earlier. Such a solution would therefore be preferable as an option, I think. But with that solution, it should be possible to exclude scripts based on runtime variables like $TEST.
This is perfect! Thanks for this script.
My project is pretty large, and I'd like to group script folders based on logical grouping of features (i.e. "Animation Code, UI Code, etc."), in a way that's unrelated to the actual script load order. This sometimes means I'll want the load order to be "Folder1/file1, Folder2/file2, Folder1/file3". 

Is there a way to specify load order independent of folder structure? It looks like the current method only allows changing load order of files within the same folder.
This turned out to be a bigger challenge to implement in an elegant way than I'd imagined. The first hurdle is obviously that the current setup uses a hash with key / value pairs as the folder definition structure, and hashes can't have duplicates of the same key. Then when you consider ordered loading for similar folders but spread out with other folders in between and no overlap, it turned out to be quite something 😉

I have it on my list though, and I'll figure out some nice way to make it possible.
How have you been handling debugging with this? I just noticed that since you're compiling everything in one giant script file, any line numbers will be from the scripts.rb file, rather than the original script.

It's not a huge problem, since I can always still open the scripts file and find the corresponding line, but it is bit of a pain when errors show up on "line 15246", rather than whatever line it's actually on in the original script.

Original thread: https://forums.rpgmakerweb.com/threads/external-scripts-framework.20589/