Common Mistakes and How to Fix Them

This is a wiki post that will grow as more common mistakes (and their solutions) are submitted. If you don't have the trust to edit this yet, feel free to propose changes in a post. If you're confused about anything, ask for clarification in a post.

If someone asks for help somewhere else and you want to guide them to a specific section here, remember you can hover over a header to get a link to it specifically.

Why is my mod stuck on loading?

There was probably an error in your code somewhere. Open up the console using ctrl + shift + i to look for error messages. They will help you figure out what’s wrong. Some of the other sections in here will help with debugging specific error messages.

My layers aren’t appearing

If the mod is loading but not displaying your layers, you probably forgot to add them to the mod files. To do that, find the modInfo property in mod.js and look for the line that looks like this:

modFiles: ["layers.js", "tree.js"],

You can either add every layer in layers.js or can add new files to the list for each layer to help keep things more organized.

Example

modFiles: ["tree.js", "prestige.js", "boosters.js", "generators.js"],

Uncaught SyntaxError: Unexpected Token

The most common cause of this error is when there is a mismatch of opening and closing parentheses or brackets. Check whatever code you most recently wrote and make sure you open and close all your code blocks correctly.

Example

...,
effect() {
    if (hasUpgrade("p", 12) {
        return new Decimal(1);
    return new Decimal(0);
},

should become (note there’s a new ) and a new })

...,
effect() {
    if (hasUpgrade("p", 12)) {
        return new Decimal(1);
    }
    return new Decimal(0);
},

Uncaught SyntaxError: Unexpected identifier

This means you’ve written something but forgotten part of the javascript syntax. Most often this is something like not separating properties in an object with commas.

Example

{
    title: "something"
    id: "foo"
    ...
}

should become

{
    title: "something",
    id: "foo",
    ...
}

Cannot read property of undefined?

This means you’re trying to access something on an object that doesn’t exist. Typically this is caused by mis-remembering what properties are on what objects.

For example, you might try to access the amount of prestige points you have by doing something like player.prestige.points when it would actually be player.p.points, because it uses the layer id not the layer name.

Uncaught TypeError: add is not a function

This applies to any property name, but add is a very common one. Typically this happens because you’ve returned a Number from some function instead of a Decimal, and are then trying to call one of Decimal’s methods on the Number. Make sure to return Decimals from every function that returns a numeric value.

Example

...,
effect() {
    return getBuyableAmount('p', 11).add(1).log10();
},
sellOne() {
    ...
    setBuyableAmount('p', 11, amount - 1);
},

should become

...,
effect() {
    return getBuyableAmount('p', 11).add(1).log10();
},
sellOne() {
    ...
    setBuyableAmount('p', 11, amount.sub(1));
},

Why is my number Infinity?

Usually this is a result of creating a Decimal with a number that is too large to fit in a JavaScript number (greater than e308). The solution is to create a Decimal with a string instead.

Example

new Decimal(1e400) // returns a Decimal with value Infinity

should become

new Decimal("1e400") // returns a Decimal with value 1e400

Why is my number NaN?

Typically this means you’re doing a math operation that has no value, like dividing by 0 or taking a log of 0. These can often appear to be working for some amount of time, if you currently have a non-zero amount of some resource, but it then gets reset later on. The solution is typically ensuring the operand is above 0 by using .max(1) or .add(1). These do affect the results of the formula so make sure to work out the most appropriate fix for your given situation.

Example

return player.p.points.div(player.points); // Will be NaN when player.points is 0

return player.p.points.log10(); // Will be NaN when player.p.points is 0

should become

return player.p.points.div(player.points.max(1));

return player.p.points.add(1).log10();

In those examples I picked max for the first line because player.points increases so fast that the time it’s value is between 0 and 1 is very short, and max will have less impact on the end result of the formula. For the second example you’d probably want the different between 0 and 1 prestige points to make a difference, so I add 1 instead, even though this will have more of an impact on the result of the formula.

3 Likes