RPGMakerMV: How To Eval

RPGMakerMV: How To Eval

Eval is the secret we don’t talk about. For RPGMakerMV plugin developers, learning to use eval can change the game. So, let’s talk about what it does and how to use it.

 

What Does Eval Do For You

Eval allows you to interpret strings as JavaScript. Now, many devs would advise against using it in a traditional development sense. But for RPGMakerMV, you can use it to create limited scopes where people can run JavaScript code. Leveraging this power can allow people with little JavaScript experience a way to play with the game variables in a safe way. This leads me to how to use it.

 

How To Use Eval

To use eval wrap a string inside the function called eval, the result will then be returned to you. Here’s a quick example:

eval("3 + 3"); //Returns 6
This number will be returned to you and you can use it however you like; a simple example, but it has a lot of power behind it. Another important part of eval is that it’s local to the function you’re in. This is important and offers us the benefits of safety in our plugin. Meaning, we can offer select variables to be evaluated. Here’s an example use of eval that could apply to RPGMakerMV: returning actor names.

eval(" $gameActors.actor(1).name().toUpperCase()") //Returns the Game_Actor name of actor 1 in RPGMakerMV in uppercase.

This snippet of code would return the actor name in all uppercase. This could be great for demonstrating shouting in your game for specific words. This is just one use, you could even showcase the actor stats with this kind of evaluation. Here’s an example of using it with my own game to display the time in milliseconds.

 

As you can see, that’s the time in milliseconds from when the window was open and Date.now() was evaluated. Now, I’ve also turned this into a plugin, which I will be releasing soon!

Anyway, try out eval on your own; it can be useful to your plugin development. Happy creating!

Leave a Reply

Your email address will not be published.