Friday Script – Plugging Into Yanfly’s Message System

If you want to get the most out of RPG Maker, learn Ruby. In the meantime, lots of talented scripters have done the work for you. Every Friday, The Iron Shoe features a fun script and goes into detail about how to use it. It also covers a little bit of Ruby each time so you can make even more out of the script.

You know I love me some Yanfly, particularly his message system. I’ve mentioned it before for the ability to refer to item names dynamically – huge for any attempts to randomize loot. I’ve shown screenshots of the awesome nameplate, critical for Vidar since the identity of the NPCs is central to the game.

But reddit user Gavlan_Wheel wanted to do something new with it. Specifically, he wanted to change the font color of the name displayed dynamically, allowing the player to choose by setting a variable. With user Sarkilas’s help, we got him a working solution.

You can download Yanfly’s script here. Drop it into your game and let’s get cracking!

Store as Variable

Open up the script and find the line where you set the font for the name. It’ll look a little like this:

The integers - like 6 - refer to the colors as identified in your window graphic. Just count them up!

The integers – like 6 – refer to the colors as identified in your window graphic. Just count them up!

Gavlan_Wheel knew he wanted to set this to a variable, rather than a static number. So what’s the problem? Well, because RPG Maker uses a form of Ruby, it’s going to run through (and execute) all of the code that it can the minute you start the program. Not when you click New Game or Continue, but in the space immediately before the title screen is displayed. And at this point, $game_variables doesn’t exist! So if assign our font color to $game_variables[1], for example, you’ll get an error.

Instead, we’re going to tell the script to ignore this section for now, and only evaluate the name window color when it needs to; that is, when it’s drawing a name. Replace that line with:

NAME_WINDOW_COLOUR   = Proc.new{$game_variables[id]}

Whatever variable you’re using should go where it says id. What we’ve done is changed our variable from an integer to a Proc, a little line of code that we can run rather easily.

Call the Proc

There’s one more change we now have to make. Because we’re using a function, we need to “call” that function and ask it to give us the correct value any time we want to use name_window_colour. Find the line where it’s actually used, around here:

This is where the name is actually drawn, using whatever is stored in the color variable set up above.

This is where the name is actually drawn, using whatever is stored in the color variable set up above.

And after NAME_WINDOW_COLOUR, write “.call” – your line will now read:

@text = sprintf("\eC[%d]%s", YEA::MESSAGE::NAME_WINDOW_COLOUR.call, @text)

Now, in your game, as you control the variable you identified, you’ll change the font accordingly. You can use this trick to start setting up player choice for font colors, which is always nice since monitor brightness varies 🙂

Message

Message4

Message5

 

Advertisements

One thought on “Friday Script – Plugging Into Yanfly’s Message System

  1. Pingback: Chat Mapper – Getting Fancy | The Iron Shoe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s