The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Event Systems => Topic started by: Strak on May 07, 2010, 12:57:51 AM

Title: [VX] In-Game Font Changer
Post by: Strak on May 07, 2010, 12:57:51 AM
In-Game Font Changer

This is something I discovered while working on my project, Bloodstained Hands. It's a useful little bit of code that allows you to change the font in-game of battle options, the menu, and if you aren't using too many complicated scripts that change the font, it can also change the font of the text boxes too.

In order for this to work, however, you do need to alter the code of one script. In "Main" below Begin and Graphics.freeze just put these two lines:

  Font.default_name = ["Font_Name"]
  Font.default_size = 20

The Font name can be changed to whatever you want, and so can the font size, but you may want to keep to fonts that are common to all computers (Arial, Arial Black, Verdana,  ect). You may also want to experiment with sizes to make sure there are no words cut off.

By the way, that code does not belong to me. I got it from a script by Woratana.

Now then, changing the font in-game!
You can do this anytime you want. Just create an event that looks like this:

@>Script: Font.default_name = ["Font_Name"]
@>Script: Font.default_size = Font_Size
(Where Font_Name is the name of the font you want to use and Font_Size is the size you want to use.)

Yes, the script is exactly the same as what was entered in Main. Yes, it can be used in-game. Yes, it is cool. You can use this for some pretty cool things, for example, an epic scene with the last boss of the game where the font for his voice is really big and creepy and the font for the main character is normal. Or you could create an item that calls a common event that sets game settings in which you could set the font (or if you have a special menu script, call it from there). The event system I use looks like this:

@>Show Choices: Verdana, Arial Black, Pristina
 :  When [Verdana]
    @>Script: Font.default_name = ["Verdana"]
    @>Script: Font.default_size = 20
    @>Set Variable [0001:Font] = 1
    @>
 :  When [Arial Black]
    @>Script: Font.default_name = ["Arial Black"]
    @>Script: Font.default_size = 23
    @>Set Variable [0001:Font] = 2
    @>
 :  When [Pristina]
    @>Script: Font.default_name = ["Pristina"]
    @>Script: Font.default_size = 30
    @>Set Variable [0001:Font] = 3
    @>
 :  Branch End
@>

Basically, what this does is show some choices as to what font you want to use, and sets the font to the one you selected. In addition, it sets the font size to fit in the window properly and it sets a variable to a number representing that font. The variable is used in a slightly different event that is necessary to make this event work properly. See, the problem with this system is that when the game is reset, so is the default font. So, once you reload your game, the font is back to normal. This can be fixed by using the following event:

@>Conditional Branch: Variable [0001:Font] == 1
    @>Script: Font.default_name = ["Verdana"]
    @>Script: Font.default_size = 20
 :  Else
    @>Conditional Branch: Variable [0001:Font] == 2
    @>Script: Font.default_name = ["Arial"]
    @>Script: Font.default_size = 23
     :  Else
        @>
     :  Branch End
    @>
 :  Branch End

What this does is reads what number the Font variable is set to, and then sets the font to whatever font that number represents. This can be done for as many fonts as you want. The trick with this, however, is that it has to be running at all times in all maps. The easiest way to do this is to set is to a common event with a parallel process activated by a switch.

So that is the in-game font changer. Credit goes to Woratana for the code, you don't need to credit me for the system. Although you can if you want to and feel nice. Feedback is appreciated.

Thought I might just mention this now, although it can also be seen in the comments below, you must have all custom fonts included in the DL of your game.
Title: Re: Font Changer!
Post by: Grafikal on May 07, 2010, 01:02:48 AM
Not bad. Don't forget that any custom fonts would have to be included with the game and installed before gameplay.
Title: Re: Font Changer!
Post by: Strak on May 07, 2010, 01:12:24 AM
I suppose that's true... well, that certainly makes it easier to make sure the computer has the font installed! :D
Title: Re: Font Changer!
Post by: Strak on May 07, 2010, 01:48:50 AM
Ah, I have discovered a minor error. Nothing serious, and it can probably be fixed easily, but I'll bring it to everyone's attention now. While this DOES change the font in-game, the font will revert back to the default font when you re-open the game again, until you change it again in-game. Another note is that if you change the font in one file, the font is changed for every file in the game. I will fix this ASAP.
Title: Re: Font Changer!
Post by: Strak on May 07, 2010, 02:18:29 AM
Alright, I found a mediocre way of fixing this problem, but it IS a bit tedious. It does work though, and it not only resets the font on one file, but it makes sure that each separate file can have its own font.

(1) Every time you change the font in-game, set a variable to a value that represents that font. Example:

@>Script: Font.default_name = ["Verdana"]
@>Script: Font.default_size = 20
@>Control Variables: [0001:Font] = 1

(2) Make an event that looks like this:

@>Conditional Branch: Variable [0001:Font] == 1
    @>Script: Font.default_name = ["Verdana"]
    @>Script: Font.default_size = 20
 :  Else
    @>Conditional Branch: Variable [0001:Font] == 2
    @>Script: Font.default_name = ["Arial"]
    @>Script: Font.default_size = 23
     :  Else
        @>
     :  Branch End
    @>
 :  Branch End

Basically, this event should set the default font to whatever font the variable representing it is set to. You can make as many Conditional Branches as need be, for as many fonts as you are using. The event should be a parallel process, and should constantly be running.

(3) This is the tedious part. Place this event on every map in the game. I know this isn't the BEST way to deal with this problem, but it gets the job done.
Title: Re: Font Changer!
Post by: cozziekuns on May 07, 2010, 03:05:52 AM
Alright, I found a mediocre way of fixing this problem, but it IS a bit tedious. It does work though, and it not only resets the font on one file, but it makes sure that each separate file can have its own font.

(1) Every time you change the font in-game, set a variable to a value that represents that font. Example:

@>Script: Font.default_name = ["Verdana"]
@>Script: Font.default_size = 20
@>Control Variables: [0001:Font] = 1

(2) Make an event that looks like this:

@>Conditional Branch: Variable [0001:Font] == 1
    @>Script: Font.default_name = ["Verdana"]
    @>Script: Font.default_size = 20
 :  Else
    @>Conditional Branch: Variable [0001:Font] == 2
    @>Script: Font.default_name = ["Arial"]
    @>Script: Font.default_size = 23
     :  Else
        @>
     :  Branch End
    @>
 :  Branch End

Basically, this event should set the default font to whatever font the variable representing it is set to. You can make as many Conditional Branches as need be, for as many fonts as you are using. The event should be a parallel process, and should constantly be running.

(3) This is the tedious part. Place this event on every map in the game. I know this isn't the BEST way to deal with this problem, but it gets the job done.

You could just make it a common event, and set it to parallel process it with a switch.
Title: Re: Font Changer!
Post by: Strak on May 07, 2010, 03:34:40 AM
That is a very good idea, I hadn't thought of that.
Title: Re: In-Game Font Changer
Post by: digdarkevil on August 11, 2012, 04:28:22 PM
If You Are Using A Costum Message System Like Modern Allegra's ATS,
You Could Do This In Order To Have Your Fonts In Messages.

I'm Using This In My Game Right Now And It Work Well.

Like In Your Exemple With The "Font" Variable Above, You Use A Conditionnal Branch In Order To Get Your Font Back After A Reset. What I Did Also Include That Variable. Create A New Event And Add As Many Pages As The Number Of Fonts Your Character Can Use In Your Game, As For Me It's 3. It Could Take Long Adding This To All Of My Events But At Least It Work. On Each Pages Put One Condition Of Activation At the Very Left Of Your Page:

@>Variable:Font
Equal To (The First Number Of The Font Your Character Can Choose)

And On This Page Add The Code \fn[thenameodyourfirstfont] at The Beginning Of Each Text Box. As For The Other Pages, Only Change The Variable And The text Code  :)

Hope It Helped !  :lol:

Title: Re: In-Game Font Changer
Post by: Acolyte on August 11, 2012, 05:04:19 PM
I'm not sure I follow what you're trying to say, but

Modern Allegra

I lol'd :V


Title: Re: In-Game Font Changer
Post by: digdarkevil on August 12, 2012, 12:03:03 AM
sorry for my bad english :-\