Tired of copy and pasting the same ChoiceScript code in every scene because you have a chunk (or chunks!) common code you need to use throughout your game? Maybe you’ve been shying away from writing a certain ChoiceScript game because of the complexity of the code you would have to copy and paste in order to fulfill your idea. In either case, this mod is for you! Now instead of copy and pasting, you can have all of your common ChoiceScript code in a single file, in this case “choicescript_global.txt” (located in the ‘scenes’ folder), and you can *gosub to them from ANY scene! This mod will, with every scene in your game, automatically load the global code and append it to the current scene.
How to use? Simple! Just put all of the code you need in the file “choicescript_global.txt”, located in the “scenes” folder, then call the code chunks using the ‘*gosub’ command!
If you want to add global CS function capability to your current project, you will need the following:
-In the file “scene.js”, either comment out or replace the function loadScene() with the one from the mod
-Also in the same file, add the function loadGlobalScene() from the mod version of “scene.js” to your game’s version
-In the “scenes” folder, create a file named “choicescript_global.txt”
… After this, you should be able to use global CS functions!
A few things to keep in mind:
-I would refrain from calling to any global functions in the Stats scene, as this may have unexpected results, though I have not tested this to see what would happen
-I wouldn’t use “*goto” to call to a global function, however using “*goto” within a global function itself is fine as long as you remember to eventually use “*return” to branch back to the main scene
-Make sure that you name all of your global CS functions in a unique manner, perhaps with a prefix of “g_” or the like, else if there is another label with the same name in any of your normal scene files, you will get an error
If you have any questions or find any errors/bugs, or if you have comments or suggestions, please let me know. Until then, happy ChoiceScripting!