Dumb question about text formatting in scripts

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Hey, it's been a wile...
there's this issue that has been bugging me for a couple of days; I have two scripts (well several actually, but I'll use these two as an example) for two different sub-menus in my game, one being a "option menu" and the other being a "gamepad config" menu inside the option menu;

As with many script before them, there is some part within the script code where you write stuff, and that stuff is then written on your menu in-game.

from this:

upload_2018-11-16_19-25-23.png

to this:

upload_2018-11-16_19-25-12.png

and as you can see, text formating works ok; "Note:" appears in red exactly as I wanted to.

Unfortunately the same can't be said about the second script:

upload_2018-11-16_19-25-4.png

Even 'tho I use the same formatting and both scripts are actually by the same dude

upload_2018-11-16_19-20-48.png

so the question is... why some scripts recognize text formatting and some don't?
 

Attachments

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
I have the feeling that the 2nd menu is getting that \\I[49] as a result of a function, which is being returned as a string.
so, it's passed down as a string.

at some point in between the reading and the displaying, there should be a conversion to icon.
the plugin data is not the problem.... the handling of that data is.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
Only the draw_text_ex method can process these text codes, the simple draw_text method can't.

From what I see, the second example text is centered, so my guess is that that one uses draw_text, while that help text uses draw_text_ex.
There is no alignment option for draw_text_ex by default, that's why I assumed the above. Of course, it's possible to add that fairly easily for any experienced scripter, so this is still just a guess.

Also, I don't remember which string format uses which text code "starter", but one of them uses a single \ while the other uses a double \ sign or a \e combined.
It depends on the string format you used: "one format - quotes", 'other format - apostrophes' .

Without seeing the scripts in question, that's about all anyone could tell you.
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
here's the "option" script:

https://forums.rpgmakerweb.com/index.php?threads/settings-menu.43612/

and here is the one that has to do with controller setup (it's by the same guy but I can't seem to find it on this forum so I'll paste it from my game;

#===============================================================================
# Personalizzazione controller di Holy87
# Difficoltà utente: ★
# Versione 1.0
# Licenza: CC. Chiunque può scaricare, modificare, distribuire e utilizzare
# lo script nei propri progetti, sia amatoriali che commerciali. Vietata
# l'attribuzione impropria.
#===============================================================================
# Questo script vi permette di utilizzare aggiungere nelle opzioni di gioco due
# nuovi comandi che permetteranno al giocatore di configurare a piacimento i
# tasti del proprio controller e la potenza della vibrazione.
#===============================================================================
# Istruzioni: inserire lo script sotto Materials, prima del Main e sotto gli
# script XInput e Opzioni di gioco. I due script sono necessari per il corretto
# funzionamento, pena crash all'avvio.
# Sotto è possibile configurare i testi per le voci e i comandi personalizzabili.
#===============================================================================

#===============================================================================
# ** Impostazioni dello script
#===============================================================================
module ControllerSettings
#--------------------------------------------------------------------------
# * Testi per il menu Opzioni
#--------------------------------------------------------------------------
CONTROLLER_COMMAND = 'Keys Configuration'
CONTROLLER_HELP = 'Set up your Controller''s Keys'
VIBRATION_COMMAND = 'Vibration'
VIBRATION_HELP = 'Set up Your controller''s Vibration Intensity'
RESET_COMMAND = 'Restore Default'
NO_KEY_SET = 'No Key Selected'
HELP_INPUT = 'Press the desired key on your Gamepad'
HELP_KEY = 'Controller Configuration:'
#--------------------------------------------------------------------------
# * Tasti configurabili nella schermata.
#--------------------------------------------------------------------------
INPUTS = [:UP, :DOWN, :LEFT, :RIGHT, :C, :B, :A, :X, :Z, :ATK, :Y, :R, :L, :FLT, :pAU, :oPT, :MAP, :DOC]
#--------------------------------------------------------------------------
# * Tasti da escludere nella selezione
#--------------------------------------------------------------------------
EXCLUDED = [:L_AXIS_X, :L_AXIS_Y, :R_AXIS_X, :R_AXIS_Y, :LEFT_THUMB, :RIGHT_THUMB]
#--------------------------------------------------------------------------
# * Descrizione dei comandi
#--------------------------------------------------------------------------
INPUT_DESCRIPTION = {
:UP => 'Move Up',
:DOWN => 'Move Down',
:LEFT => 'Move Left',
:RIGHT => 'Move Right',
:C => 'Action/Confirm',
:B => 'Menu/Cancel',
:A => 'Run',
:X => 'Aim (Firearm)',
:Y => 'Reload',
:Z => 'Aim (Knife)',
:L => 'Previous Weapon',
:R => 'Next Weapon',
:ATK => 'Shoot/Attack',
:FLT => 'Toggle Flashlight',
:pAU => 'Pause',
:MAP => 'Open Map',
:oPT => 'Options',
:DOC => 'Files',
}
end

#===============================================================================
# ** ATTENZIONE: NON MODIFICARE SOTTO QUESTO SCRIPT SE NON SAI COSA TOCCARE! **
#===============================================================================



$imported = {} if $imported == nil
$imported['H87-PadSettings'] = 1.0

#===============================================================================
# ** ControllerSettings
#-------------------------------------------------------------------------------
# Some core methods
#===============================================================================
module ControllerSettings
#--------------------------------------------------------------------------
# * Key scene command creation
#--------------------------------------------------------------------------
def self.create_keys_command
command = {:type => :advanced, :method => :call_keys,
:text => CONTROLLER_COMMAND, :help => CONTROLLER_HELP,
:condition => 'Input.controller_connected?'}
command
end
#--------------------------------------------------------------------------
# * Vibration command creation
#--------------------------------------------------------------------------
def self.create_vibration_command
command = {:type => :bar, :method => :update_vibration,
:text => VIBRATION_COMMAND, :help => VIBRATION_HELP,
:condition => 'Input.controller_connected?',
:var => 0, :max => 100, :val_mt => :get_vibration,
:distance => 10, :default => 100}
command
end
#--------------------------------------------------------------------------
# * Excluded keys from the configuration
#--------------------------------------------------------------------------
def self.excluded_commands; EXCLUDED; end
end

#--------------------------------------------------------------------------
# * Insert to Options list
#--------------------------------------------------------------------------
H87Options.push_keys_option(ControllerSettings.create_keys_command)
H87Options.push_keys_option(ControllerSettings.create_vibration_command)

#===============================================================================
# ** Vocab
#-------------------------------------------------------------------------------
# Scome vocabs
#===============================================================================
module Vocab
#--------------------------------------------------------------------------
# * Command Input friendly name
#--------------------------------------------------------------------------
def self.command_name(input)
ControllerSettings::INPUT_DESCRIPTION[input]
end
#--------------------------------------------------------------------------
# * Help text to input
#--------------------------------------------------------------------------
def self.input_window_text
ControllerSettings::HELP_INPUT
end
#--------------------------------------------------------------------------
# * Help text to key config
#--------------------------------------------------------------------------
def self.key_config_help
ControllerSettings::HELP_KEY
end
end

#===============================================================================
# ** Option
#-------------------------------------------------------------------------------
# Custom game pad methods
#===============================================================================
class Option
#--------------------------------------------------------------------------
# * Calls the key configuration scene
#--------------------------------------------------------------------------
def call_keys
Sound.play_ok
SceneManager.call(Scene_KeyConfig)
end
#--------------------------------------------------------------------------
# * Updates the user vibration (and vibrate)
#--------------------------------------------------------------------------
def update_vibration(value)
$game_system.set_vibration_rate(value)
Input.vibrate(100, 100, 20) if SceneManager.scene_is?(Scene_Options)
end
#--------------------------------------------------------------------------
# * Gets the user configured vibration
#--------------------------------------------------------------------------
def get_vibration
$game_system.vibration_rate
end
end

#===============================================================================
# ** Scene_Options
#-------------------------------------------------------------------------------
# Controller check process
#===============================================================================
class Scene_Options < Scene_MenuBase
alias h87contr_settings_update update unless $@
alias h87contr_settings_start start unless $@
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
def start
h87contr_settings_start
@connected = Input.controller_connected?
end
#--------------------------------------------------------------------------
# * Update process
#--------------------------------------------------------------------------
def update
h87contr_settings_update
update_controller_connection
end
#--------------------------------------------------------------------------
# * Checks if the controller is connected/disconnected during this
# scene, and refresh the window
#--------------------------------------------------------------------------
def update_controller_connection
if @connected != Input.controller_connected?
@connected = Input.controller_connected?
@option_window.refresh
end
end
end

#===============================================================================
# ** Scene_KeyConfig
#-------------------------------------------------------------------------------
# Keys configuration scene
#===============================================================================
class Scene_KeyConfig < Scene_MenuBase
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
def start
super
create_help_window
create_keys_window
create_input_window
end
#--------------------------------------------------------------------------
# * Help window creation
#--------------------------------------------------------------------------
def create_help_window
super
@help_window.set_text(Vocab.key_config_help)
end
#--------------------------------------------------------------------------
# * Keys list window creation
#--------------------------------------------------------------------------
def create_keys_window
y = @help_window.height
@keys_window = Window_PadKeys.new(0, y, Graphics.width, Graphics.height - y)
@keys_window.set_handler:)ok, method:)check_command))
@keys_window.set_handler:)cancel, method:)return_scene))
@keys_window.set_handler:)reset, method:)reset_keys))
@keys_window.activate
@keys_window.index = 0
end
#--------------------------------------------------------------------------
# * Input window creation
#--------------------------------------------------------------------------
def create_input_window
@input_window = Window_Input_Key.new(method:)check_selected_key))
end
#--------------------------------------------------------------------------
# * Checks the selected command
#--------------------------------------------------------------------------
def check_command
if @keys_window.item == :reset
reset_keys
else
open_input_window
end
end
#--------------------------------------------------------------------------
# * Reset all custom keymap
#--------------------------------------------------------------------------
def reset_keys
$game_system.create_default_key_set
@keys_window.refresh
@keys_window.activate
end
#--------------------------------------------------------------------------
# * Opens the key input window
#--------------------------------------------------------------------------
def open_input_window
@input_window.open
end
#--------------------------------------------------------------------------
# * Checks what the user chosen. If the controller is accidentally
# disconnected, returns to the previous scene.
#--------------------------------------------------------------------------
def check_selected_key
key = @input_window.selected_key
if key == 0
return_scene
else
$game_system.xinput_key_set[@keys_window.item] = key
@keys_window.refresh
@keys_window.activate
end
end
end

#===============================================================================
# ** Window_PadKeys
#-------------------------------------------------------------------------------
# This window contains the editable commands
#===============================================================================
class Window_PadKeys < Window_Selectable
#--------------------------------------------------------------------------
# * Object initialization
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@data = ControllerSettings::INPUTS + [:reset]
refresh
end
#--------------------------------------------------------------------------
# * Item max
#--------------------------------------------------------------------------
def item_max; @data ? @data.size : 0; end
#--------------------------------------------------------------------------
# * Item (as Symbol)
#--------------------------------------------------------------------------
def item; @data[index]; end
#--------------------------------------------------------------------------
# * Draw item
#--------------------------------------------------------------------------
def draw_item(index)
key = @data[index]
if key
if key != :reset
draw_key_command(key, index)
else
draw_reset_command(index)
end
end
end
#--------------------------------------------------------------------------
# * Draws a command with friendly name and controller input
#--------------------------------------------------------------------------
def draw_key_command(key, index)
rect = item_rect(index)
rect.width -= 4
change_color(normal_color)
draw_text(rect.x, rect.y, rect.width/2, line_height, Vocab.command_name(key))
if $game_system.xinput_key_set[key]
change_color(crisis_color)
draw_text(rect.width/2, rect.y, rect.width/2, line_height, Vocab.gamepad_key($game_system.xinput_key_set[key]), 1)
else
change_color(knockout_color)
draw_text(rect.width/2, rect.y, rect.width/2, line_height, ControllerSettings::NO_KEY_SET, 1)
end
end
#--------------------------------------------------------------------------
# * Draws the reset command
#--------------------------------------------------------------------------
def draw_reset_command(index)
rect = item_rect(index)
rect.width -= 4
change_color(normal_color)
draw_text(rect, ControllerSettings::RESET_COMMAND, 1)
end
#--------------------------------------------------------------------------
# * Handling Processing for OK and Cancel Etc.
#--------------------------------------------------------------------------
def process_handling
return unless open? && active
process_reset if handle?:)reset) && Input.trigger?:)CTRL)
super
end
#--------------------------------------------------------------------------
# * CTRL key called
#--------------------------------------------------------------------------
def process_reset
call_reset_handler
end
#--------------------------------------------------------------------------
# * Calls the reset process
#--------------------------------------------------------------------------
def call_reset_handler
call_handler:)reset)
end
end

#===============================================================================
# ** Window_Input_Key
#-------------------------------------------------------------------------------
# This window awaits the user input with the game pad
#===============================================================================
class Window_Input_Key < Window_Base
attr_reader :selected_key
#--------------------------------------------------------------------------
# * Object initialization
# @param [Method] method
#--------------------------------------------------------------------------
def initialize(method)
width = calc_width
height = fitting_height(2)
@closing_method = method
@selected_key = nil
super(0, 0, width, height)
center_window
self.openness = 0
self.back_opacity = 255
refresh
end
#--------------------------------------------------------------------------
# * Refreshj
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_text(0, 0, contents_width, contents_height, Vocab.input_window_text, 1)
end
#--------------------------------------------------------------------------
# * Window opening with input check
#--------------------------------------------------------------------------
def open
@old_packet = XInput.get_state.packet_number
super
end
#--------------------------------------------------------------------------
# * Update process with key scanning
#--------------------------------------------------------------------------
def update
super
update_key_scan
end
#--------------------------------------------------------------------------
# * Detects the first user input. If the controller is disconnected,
# closes the window.
#--------------------------------------------------------------------------
def update_key_scan
return unless open?
keymap = XInput.get_key_state.keys - ControllerSettings.excluded_commands
unless Input.controller_connected?
@selected_key = 0
close
return
end
if keymap.any? && XInput.get_state.packet_number != @old_packet
@selected_key = keymap.first
close
end
end
#--------------------------------------------------------------------------
# * Centra la finestra nel campo
#--------------------------------------------------------------------------
def center_window
self.x = (Graphics.width - self.width)/2
self.y = (Graphics.height - self.height)/2
end
#--------------------------------------------------------------------------
# * Closes the window calling the refresh method
#--------------------------------------------------------------------------
def close
super
@closing_method.call
end
#--------------------------------------------------------------------------
# * Gets the window width
#--------------------------------------------------------------------------
def calc_width; Graphics.width; end
end

There is another script that actually allows controller to work. It's probably not related to the issue because it's just a text formatting problem, the gamepad itself actually works; I wanted to post it but it's too long and the forum won't let me, so maybe I'll post it separately if it's needed.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
Yeah, just like I suspected:
Code:
draw_text(rect.width/2, rect.y, rect.width/2, line_height, Vocab.gamepad_key($game_system.xinput_key_set[key]), 1)
As you can see, the key names are drawn by draw_text, and not draw_text_ex, hence you can't use message codes in their name settings.
Rewriting it to use draw_text_ex instead will allow you to use message codes, but you will lose the centered text alignment, it will be left aligned instead, unless someone adds an alignment option for this drawing method too.
If you are fine with that, you can replace that line with this one:
Code:
draw_text_ex(rect.width/2, rect.y, Vocab.gamepad_key($game_system.xinput_key_set[key]))
But for future reference, please use the CODE tag for block of codes in your posts, otherwise it will end up just like the one you posted now, full with smileys and without proper formatting. The CODE tag is right under the SPOILER tag in the post editor, so it should be easy enough to find.
 
Last edited:

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
But for future reference, please use the CODE tag for block of codes in your posts, otherwise it will end up just like the one you posted now, full with smileys and without proper formatting. The CODE tag is right under the SPOILER tag in the post editor, so it should be easy enough to find.
aw jeeze, I knew I forgot something along the way lol
My bad, I haven't posted in a wile and for some reason I completely forgot about the CODE tag :(

Anyway, I did as you said and now I'm getting this error wherever I open up the menu:

upload_2018-11-17_15-29-37.png
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
That's because I forgot to replace the method name to draw_text_ex, sorry. >.>
I edited my previous reply, fixed the code to be used, try it with that.
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
That's because I forgot to replace the method name to draw_text_ex, sorry. >.>
lol that happens :p

Anyway, It worked!

upload_2018-11-17_17-19-17.png

It's also aligned fairly decently, so I may leave it like that when I'll put other icons in
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top