Modding Resources: Installing Mods | Creating Mods | Basic Code Examples | Creating a Character | Audio and Visual Effects | The Automator | User Interface | Graph Editor

Basic Code Examples

See in the Clicker Heroes 2\mods\examples folder for a mod made using the code described here.

Editing Static Data

The onStaticDataLoaded function of your mod allows you to edit the fields in the file staticdata.txt. You can open the staticdata.txt file in FlashDevelop to see what is handled here, by default this file is installed at this location on Windows:

    C:\Program Files (x86)\Steam\steamapps\common\Clicker Heroes 2\data\staticdata.txt

For an example of how this file is structured, if we look at the section for "themes" there are several entries that look like this:

	"1": {
	    "id": 1,
	    "name": "Grass",
	    "environments": "1,2,3,4"


Each of these has information about the different themes, or world types, in this case the Grass world type, and sets the environments that will show up for that world, for the Grass world they are the environments with IDs 1, 2, 3, and 4, in that order. We can then look in the "environments" section to find more information about each of the environments associated with these IDs, such as their names (plains, grasslands, countryside, and farm), and the IDs of all the monsters that can spawn there, among other things.

Example syntax for how to edit a field in staticdata.txt:

	public function onStaticDataLoaded(staticData:Object):void 
		staticData["themes"]["1"]["environments"] = "4,3,2,1";

The above code will change the environments that will load for theme 1 (Grass worlds) to be 4, 3, 2 and 1 (farm, countryside, grasslands, and plains), in that order.

Creating a Skill

To create a skill, you will need to create a new Skill object, fill out basic information about this new skill such as it's name, cooldown, and mana/energy cost, and then add the skill to Character's staticSkillInstances, which is used by all characters installed in the game.

First you will need to import models.Skill in your mod. Here is an example template for creating a new skill in onStartup:

	var exampleSkill:Skill = new Skill;
	exampleSkill.modName = MOD_INFO["name"]; = "Example Skill";
	exampleSkill.description = "";
	exampleSkill.cooldown = 1000;
	exampleSkill.iconId = 100;
	exampleSkill.manaCost = 0;
	exampleSkill.energyCost = 1;
	exampleSkill.minimumAscensions = 0;
	exampleSkill.effectFunction = exampleEffect;
	exampleSkill.ignoresGCD = false;
	exampleSkill.maximumRange = 9000;
	exampleSkill.minimumRange = 0;
	exampleSkill.tooltipFunction = function():Object { 
		return this.skillTooltip("Skill Tooltip");
	Character.staticSkillInstances[] = exampleSkill;

The effectFunction is the name of the function that determines what effect occurs when a player uses the skill. You can peruse the file that is provided with the game in the mods\active folder, to see how Cid's skills work and get some ideas, but here is an example that will do 100 damage to the next monster in the world:

	private function exampleEffect():void 
		var monster:Monster =;

		if (monster) 
			var attackData:AttackData = new AttackData();
			var damageNumber:BigNumber = new BigNumber(100);    
			attackData.damage = damageNumber;


For the above code you will need to import models.Monster, models.AttackData, and com.playsaurus.numbers.BigNumber.

The if (monster) condition checks to make sure there is actually a target to so that there won't be an error if no monster is found. AttackData is an object that has information about an attack, including how much damage is done, but also things like whether or not the attack is a critical hit. Every character has an attack function that takes an AttackData object, and if you want you can overwrite this function for your own characters to handle attacks differently. Since the damage in AttackData can be set to be incredibly large, it requires a BigNumber that you must create for the value you want.

Editing Pre-Existing Characters

There are several ways to edit pre-existing characters such as Cid, depending on what your goal is.

Certain things need to be edited before a character instance has been created, so that the these changes will be taken into account when it is. To do this, you can access certain fields from Characters' startingDefaultInstances object in onStartup:

    Characters.startingDefaultInstances["Helpful Adventurer"]

You need to import model.Characters and make sure your mod loads after the character you are editing. One example that would require this this would be adding a skill to the list of skills a character starts with:

	Characters.startingDefaultInstances["Helpful Adventurer"].startingSkills.push("Example Skill");

The above line of code will add the "Example Skill" we created in the previous example to Cid's array of starting skills.

If you need to edit aspects of a character after the instance has been created you can use the onCharacterCreated function:

	public function onCharacterCreated(characterInstance:Character):void 
		if ( == "Helpful Adventurer") 

With the above you can add code that would apply to any character with the name "Helpful Adventurer" (aka Cid). Without the if statement, it could alter all characters. Using the onCharacterCreated method is necessary when you need the details of the character you're editing to already be created so you can access them.

An example that would require this method would be editing things like skills or skill graph nodes for a character. You can access skills from the character instance with either the getStaticSkill() or getSkill() functions. For example:

	var skill:Skill = characterInstance.getStaticSkill("MultiClick");
	skill.energyCost = 0;

Adding the above code within the if statement will change the energy cost of Cid's MultiClick skill to 0. Using getStaticSkill() here will mean that the skill will only be affected when a character first purchases it, so on characters that already have it, it will still have an energy cost. If you want to set its cost to 0 for all affected characters, you can use getSkill() instead. However, this will also overwrite any additional energy cost changes, such as the additional energy cost added by the Increased MultiClicks trait.

Another thing you can access from the character instance are the skill tree nodes. The following example placed in onCharacterCreated would let you replace the purchase function of the node "Mu" in Cid's skill tree:

	characterInstance.levelGraphNodeTypes["Mu"]["purchaseFunction"] = function() { }

See the Creating a Level Graph (aka Skill Tree) section for more information about how the level graph nodes work, and also an example of adding a new node to a pre-existing character.

Finally, there are certain functions that all characters have which are designed to be overwritten. See the section on Overriding Character Functions for a list of these functions and how to override them.

Mod Dependencies

If you are going to be making changes to a pre-existing character that have the potential to make permanent changes that can break a save created with that mod installed if it is later removed, then you will want to add a dependency to that character. A dependency will make it so that a character save created with that mod will not load if that mod is not installed. You will want to add dependencies when adding new functionality to a character, including things such as skills or automator components, as well as for creating a new character as you will of course need the character mod installed to load a save that uses that character.

In order to create a dependency you need to add the mod name to the affected character's modDependencies within the onCharacterCreated function:

	public function onCharacterCreated(characterInstance:Character):void 
		if ( == "Helpful Adventurer") 
			characterInstance.modDependencies[MOD_INFO["name"]] = true;

Be sure to remember to include the if statement to specify which character or characters require the dependency, or a dependency will be added for the saves of all characters.

More Coming Soon!

We plan to continue to add to these tutorials as development continues. If you want to do things that aren't currently covered here, you can get an idea of some of the things you can access through code completion. For example, if you type "CH2.currentCharacter.", FlashDevelop should provide a list of things you can continue with if your project has been set up correctly. You also have access to the source code for Cid, in the mods\active folder, which you can open with FlashDevelop, and you can access the main source code in CH2Library.swc using a free Flash decompiler like JPEXS.

Hopefully this will give you a start for now, and more information about CH2 code and modding will continue to come!