What to do when your formulas aren’t working

Devs that use my scripts may notice that I really like using formulas.  You might recognize this one from your default attack  damage formula

a.atk * 2 - b.def * 4

Or in the case of note-tags, you might write something sophisticated like this

<some name: a.state?(23) || a.hp < a.mhp * 0.5>

The focus of this post is not what a formula is, but what happens when

Your formula just doesn’t seem to work

We’ve run into script issues before, where the script doesn’t seem to work. What happens when it doesn’t work? You debug it:

  • Create a new project and see if the script works there
  • If it does, then we have a compatibility issue, and you need to figure out what’s causing the conflict

But what happens when a formula doesn’t work? In the best case scenario, you get an error thrown at you saying that something went wrong. If you’re using some sort of full stack trace script, it might even tell you where the error occurred.

But what happens when no error message occurs, AND you’re not getting the results you expect?

It might be a logic bug

Simple logic bug: you want the death state to be applied when your HP is 0, but you end up writing

hp > 0

So you start the battle, and you die. Why? It might take some time to figure out, and you might even need someone else to look at your work, but eventually it will become apparent that the logic you intended to write, was not what you wrote.

(For those that are not very good with formulas and might not understand what’s going on, what I wrote up there was your HP greater than 0)

Debugging the bug

Let’s say you’ve determined that there may be an issue with your formula. If it’s a formula for one my scripts, 99% of the time it’s a logic bug, because my scripts likely only expect your formula to return two types of values

  • True or False

If it’s not working, then you’re probably returning the wrong value. What you think the RM is doing, may not be what RM does. Maybe you assumed a value stores an integer, but in fact it’s storing a percentage. 1 and 0.01 are very different numbers.

  • A number. 0, 9000, 0.50, etc.

This should be somewhat more obvious, since you’ll likely see the wrong numbers being used if you’re checking the math properly.

1. Print it out

This is the easiest way to debug the formula. If you think your formula should resolve to true, print it out. The engine will tell you whether you’re right or not.

One way is to wrap your formula with msgbox calls. Using is straightforward; let’s say you were writing a formula for a note-tag called “cond”

<cond: a.state?(23)>

For most of my scripts, this basically means you’re checking whether the current subject has state 23 applied or not.

To print out the value, simply wrap it with a msgbox call:

<cond: msgbox(a.state?(23))>

And when the game is evaluating your formula, it’ll tell you whether your formula resolves to true or false.

But what if RM is wrong? Or the script itself is bugged?

2. Ask someone else

It’s possible that RM is wrong. But if you tell me that RM is getting your formula wrong, I will likely tell you that your formula probably isn’t what you think it is.

If the script is bugged, I would be more likely to believe that. However, you should assume your formula is wrong before assuming the script is bugged.

Finally, if you’ve convinced that your formula is correct and something else is the problem, consider creating a support topic on one of the RPG Maker forums such as RPGMakerWebs or RPGMakerVXAce.


You should now have an idea what to do when a formula isn’t doing what you want it to do. I admit that I’ve only listed one real technique, but that’s because I believe that’s all you really need. If it doesn’t work, then ask someone else to look at it.

Spread the word

If you liked the post and feel that others could benefit from it, consider tweeting it or sharing it on whichever social media channels that you use. You can also follow @HimeWorks to get the latest updates or suggest topics that you would like to read about.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *