[script editing help] Namebox + Variable control

Script I'm trying to edit: https://github.com/theoallen/RGSS3/blob/master/Untranslated/Namebox Window.rb
(I'll translate the help text at the top of the script if needed, but the script is easy to use without it.)

Would it be possible to control a variables for multiple namebox text results inside of the script? Example:
Variable[n] = 1 If (namebox text displayed) == "Name1"
Variable[n] = 2 If (namebox text displayed) == "Name2" (etc)

For context, I'm currently using a variable that is associated to a text sound effect script. Different variable values give different sounds.
(The code I'm using for the text SFX is from Zerbu: https://www.rpgmakercentral.com/topic/607-text-sound-effect-updated/)
Moved to: RGSSx Script Support
Bump. Any help would be appreciated.
You could try to replace this line:
Code:
MESSAGE_SOUND.play
With these:
Code:
if $game_variables[222].is_a?(Array)
  RPG::SE.new(*$game_variables[222]).play
else
  MESSAGE_SOUND.play
end
In that text sound effect script.
This will set the specified variable to be used if it's an array.
Feel free to change the variable ID, I used 222 because that was closest to my fingers. 😛

You can setup the variable with this script call:
Code:
$game_variables[222] = ["filename",volume,pitch]
Replace the stuff between the square brackets with your sound effect data.
Do this right before you want to show these message boxes, and the sound effect played will change depending on the value of the specified variable.

In case you want to set this variable dynamically within another script, you can do that too. For example:
Code:
$game_variables[222] = [actor_name+"_namebox_se",80,100]
This is just an example, and it assumes that the actor_name variable is defined and is a string.

Note that if that variable is not an array, it will play the default sound effect from the text sound effect script settings instead.
You could try to replace this line:
Code:
MESSAGE_SOUND.play
With these:
Code:
if $game_variables[222].is_a?(Array)
  RPG::SE.new(*$game_variables[222]).play
else
  MESSAGE_SOUND.play
end
In that text sound effect script.
This will set the specified variable to be used if it's an array.
Feel free to change the variable ID, I used 222 because that was closest to my fingers. 😛

You can setup the variable with this script call:
Code:
$game_variables[222] = ["filename",volume,pitch]
Replace the stuff between the square brackets with your sound effect data.
Do this right before you want to show these message boxes, and the sound effect played will change depending on the value of the specified variable.

In case you want to set this variable dynamically within another script, you can do that too. For example:
Code:
$game_variables[222] = [actor_name+"_namebox_se",80,100]
This is just an example, and it assumes that the actor_name variable is defined and is a string.

Note that if that variable is not an array, it will play the default sound effect from the text sound effect script settings instead.

Hello, thanks for your help! After reading through your reply and checking the code, I realized the mistakes inside of my edited code. The conditional branch/SE change issue I had is now solved.

For anyone trying to use both Zerbu's SFX code (either the original one or this edited one - the site is in french but the code is in english) and TheoAllen's namebox code - and want to change SFX pitch/filenames inside your game scripts rather than with script calls:
  • Put the conditional checks inside the theoallen namebox script: in "def set_text(text, right, from_list = true)" (line 130 or so.) * Also make sure you set a value with that same variable for when there is no namebox windows on-screen.
  • If you decide to do an "if $game_variables" check in the namebox script, make sure you include any sort of color or variable codes, rather than just putting in the name only inside quotes. Ex: $game_variables[X] = N if result == "\\c[1]NameHere" (which would appear as "NameHere" when you're playing). Same applies for \\v[N] and any other escape codes or symbols.
  • I also found out that there is a simpler version of this type of script feature: using some message codes will change the type of sound effect that plays. This could work if you only want 2-3 voice variations. (It's a variant of the Zerbu script, edited by Kirimash. check the last post on the thread.) I don't believe this one requires namebox scripts to work.

Original thread: https://forums.rpgmakerweb.com/threads/script-editing-help-namebox-variable-control.93583/