I have learned some new code that is really helpful! This tutorial is to introduce this code to you, and give you new capabilities with coding (unless if you already knew this).
Anyways, let me start with removing a script.
1 - Removing a Script
You probably wanna create a clone of an object, or stop running the update script of an object for some reason. Maybe you don’t want the unload script to work for an object? Well, here’s your solution:
Clip.removeScript("scriptname"); // Remove a script from "Clip"
Replace “scriptname” with the name of the script, for example, you can use “default,” “update,” “unload,” “keydown,” “mouseclick,” and etc. but keep the quotation marks to have it work! As a side note, the script will still be there once you stop the project, this code shouldn’t erase a script from the editor, but rather disable it while running the project.
2 - Adding/ Replacing a Script
I have found this code really helpful when creating clones, you just create a clone, and give its very own script! It’s a form of eval, yes, and here’s how it looks like:
Clip.addScript("scriptname","Code");
/* Replace Clips default script with Code */
This code replaces or adds to the default script of “clip” the code that you type in where it says “Code.” If there’s an error, the project will take you to the clip, and the console will give you an error, but the script you added during the project WILL NOT be in the clip, everything resets once the project pauses.
3 - Choose What Script to Run
Hmmmm… ever wondered if there was a way to tell the project to run a script whenever you want it to? Will, here’s how:
this.scheduleScript("scriptName"); // Change scriptName with name of script
Change “scriptName” with the name of the script that you want to run, and it’ll run that specific script for that specific clip. Also, you can have it run a script related to key, and define the key that being used in that script!
For example, let’s say that I wanna run the keydown script for the “a” key and the a key isn’t even pressed down, I can do this:
this.scheduleScript("keydown", {key: "a"} );
This is a really good way to have wasd and the arrow keys act the same way in a project without going through all of your code and adding them in!
(Also, in case anyone’s curious, I found this code while reading through wicks sources)