Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Variable in Skill/Magic Description

Was just wondering if there is anyway through the default setup to display a variable in the description of a Skill, Magic, or Item. And if not via RMXP's defaults maybe there is away to allow it using a script?

Thanks for the help,
MJP
 
All the descriptions show in that skinny window at the top called the "Help Window", so if we add the code from the message window that parses the variables to the help window code, descriptions will parse variables as well.

Paste above Main (Right-Click on Main, Insert. Copy script to Script Editor)
(Turn off line numbers in the code box before copying.)

Code:
class Window_Help

  #--------------------------------------------------------------------------

  # * Set Text

  #  text  : text string displayed in window

  #  align : alignment (0..flush left, 1..center, 2..flush right)

  # Add variable parsing to the help window

  #--------------------------------------------------------------------------

  alias hwv_set_text set_text

  def set_text(text, align = 0)

    # replace \v[n] with variable value

    temp = text.clone

    begin

      last_text = temp.clone

      temp.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }

    end until temp == last_text

    hwv_set_text(temp, align)

  end

end

 
 
Thank you Brewmeister, that worked very well for in battle, but out of battle in the menus. I'm not sure if that's just the way the script is set up or if it's the other scripts I'm using.

If it might be the other scripts I'm using, and if you don't mind lending me a little more of your time, I'd post what I'm using. (That is unless it's something that is easily added to what you already supplied me.)

Thank you very much,
MJP
 
I just tested it on the "default" system, and it works both in battle, and from the menu.

If you have a custom menu or battle system, it may need to be modified as well. What other scripts are you using?
 
Just add the \n section from Window_Message, and it will handle both...

Code:
class Window_Help

  #--------------------------------------------------------------------------

  # * Set Text

  #  text  : text string displayed in window

  #  align : alignment (0..flush left, 1..center, 2..flush right)

  # Add variable parsing to the help window

  #--------------------------------------------------------------------------

  alias hwv_set_text set_text

  def set_text(text, align = 0)

    # replace \v[n] with variable value

    temp = text.clone

    begin

      last_text = temp.clone

      temp.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }

    end until temp == last_text

    temp.gsub!(/\\[Nn]\[([0-9]+)\]/) do

      $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""

    end

    hwv_set_text(temp, align)

  end

end

Then you could use a dummy actor to store the custom name
 
Ok, apparently it won't let me post the script, if i include it the entire entry comes out blank. And I'm not sure why.

Direct link to where I got it.
http://redsectora.bravehost.com/rmxp_scripts/onescenecms.txt

Thanks again for the help.
MJP

Edit: Btw, again, it could just be me, but I did test the script you gave me in a blank project, and it does work in both battle and the menu like you said (TY) but if through the course of the game that variable changes, it doesn't seem to reflect the new value. Example: I have a Common event tracking how many times the player has used Cross cut, it obviously goes up by 1 every use. I check the variables to make sure they are indeed increasing which they are, but the description in both battle and the menu are still stuck at the original variable value of 0 obviously.
Thanks again.
 
Crap! "text" was acting like a pointer to the items description, so once it changed it, it was changed for good....

I updated both scripts above to use a 'temp' variable to store the string. Try it now.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top