The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: &&&&&&&&&&&&& on August 14, 2014, 06:12:30 AM

Title: [Help;-;] First Script [RMVXA]
Post by: &&&&&&&&&&&&& on August 14, 2014, 06:12:30 AM
This is the first script I've ever written.
I've been watching Diamond'd tutorials, and thought I'd give actually writing a script a try.

My idea is to make a script that allows me to change the font with a script call.

Code: [Select]
# Easy Font Changer
#===========================================================================

class Boe_Font_Chooser < Game_Variables

# Font 1
$boe_fontno1 = ["monstapix"]

# Font 2
$boe_fontno2 = ["monstapix"]

# Font 3
$boe_fontno3 = ["Arial"]

# Font 4
$boe_fontno4 = ["Arial"]

# -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =

   def initialize
   boe_font_changer
   end

   def update   
   boe_font_changer
   end
 
     def boe_font_changer
      if $font_number_boe_asj      == 0
       Font.default_name = $boe_fontno1
      elsif $font_number_boe_asj   == 1
       Font.default_name = $boe_fontno2
      elsif $font_number_boe_asj   == 2
       Font.default_name = $boe_fontno3
      elsif $font_number_boe_asj   == 3
       Font.default_name = $boe_fontno4
      else
      end
   end
end

The parts alone work "Font.default_name = $boe_fontno1" and "$boe_fontno1 = ["monstapix"]" placed by themselves changed the font, but I can't seem to get my method to activate.
Title: Re: [Help;-;] First Script [RMVXA]
Post by: D&P3 on August 14, 2014, 07:35:47 AM
Your script is fine. It doesn't work because it's not being called all the time.

Spoiler for:
Code: [Select]
class Scene_Map < Scene_Base
 
  alias boe_font_changer_smstart    start
  def start
    boe_font_changer_smstart              # Call Original 'Start' Method
    @font_chooser = Boe_Font_Chooser.new  # Make New Font Chooser
  end
 
 
  alias boe_font_changer_smupdate    update
  def update
    boe_font_changer_smupdate             # Call Original 'Update' Method
    @font_chooser.update                  # Call the 'Update' Method in BOE's Font Chooser
  end
 
end



Add this below your code and it should work.
You see, Scene_Map is a class that is updated whenever your characters are on a map. So what we do is to add a new 'instance' of the Font Chooser in the |start| method so that we only have to make a new instance one time.

Next in Scene_Map's update method we tell it to access the |update method| located within the BOE's Font Chooser instance we created in the |start| method.
Now whenever Scene_Map gets updated (which is all the time when you're on a Game Map), it'll also update BOE's Font Chooser along with it.




This means that you only need to change the variable |$font_number_boe_asj| in order for the script to work. You do not need to do anything else. :)
Though if I may make a suggestion, you can change:
Code: [Select]
$font_number_boe_asj
to:
Code: [Select]
$game_variables[10] # or $game_variables[47], etc.
so that you can change variables in the game rather than having to modify your font using a script call.
Title: Re: [Help;-;] First Script [RMVXA]
Post by: &&&&&&&&&&&&& on August 14, 2014, 08:20:24 AM
Strange. It only updates when I return to the scene. If I change the variable, and talk to somebody, nothing happens. If I change the variable then open the menu, open shop processing ect, it updates it.

I'll see if I can figure what going on.

Thank you so much for your help. ;-;
Title: Re: [Help;-;] First Script [RMVXA]
Post by: &&&&&&&&&&&&& on August 15, 2014, 02:19:10 AM
Still haven't figured out why it's not updating, but still working on that.

I made some other changes. (Ones that you suggested.)

Code: [Select]
#===========================================================================
# Easy Font Changer
#===========================================================================

class Boe_Font_Chooser < Game_Variables

# Font Controlling Variable
$boe_variable_asj = 10

# Font 0
$boe_fontno1 = ["Arial"]

# Font 1
$boe_fontno2 = ["monstapix"]

# Font 2
$boe_fontno3 = ["Times New Roman"]

# Font 3
$boe_fontno4 = ["Modern Destronic"]

# -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =
# Do Not Enter (Unless you know what you're doing)
# -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =

   def initialize
   boe_font_changer
   end

   def update           
   boe_font_changer
   end
 
     def boe_font_changer                           # Font Number
      if $game_variables[$boe_variable_asj]      == 0
       Font.default_name = $boe_fontno1
      elsif $game_variables[$boe_variable_asj]   == 1
       Font.default_name = $boe_fontno2
      elsif $game_variables[$boe_variable_asj]   == 2
       Font.default_name = $boe_fontno3
      elsif $game_variables[$boe_variable_asj]   == 3
       Font.default_name = $boe_fontno4
      else
      end
   end
 end
                                          # Update
class Scene_Map < Scene_Base
 
  alias boe_font_changer_smstart    start
  def start
    boe_font_changer_smstart              # Call Original 'Start' Method
    @font_chooser = Boe_Font_Chooser.new  # Make New Font Chooser
  end
 
 
  alias boe_font_changer_smupdate    update
  def update
    boe_font_changer_smupdate             # Call Original 'Update' Method
    @font_chooser.update                  # Call the 'Update' Method in BOE's Font Chooser
  end
 
end
Title: Re: [Help;-;] First Script [RMVXA]
Post by: Axel Mherkor on August 25, 2014, 01:23:51 AM
I think it could be because the font is defined when the bitmap is created and, after that, it uses the already created bitmap by the window instead of creating a new one. I tried to force to update the bitmap at least for the message window and even I try to create again the message window, but I think that there is something we're not taking in account... I don't know...