"Vocab script editor" insert condition switches ?

Hello.


I was wondering if it was possible to insert "Conditions switches" directely in an already


made script, like Vocab.


For exemple, to take the 1st in the list (ShopBuy = "Acheter"), I'd like to know if it's possible to change it to (ShopBuy = "Buy"),


if the $game_switches[n] = true, else if false.


I dont wanna do a translate stuff, it's just to give an exemple. I'd like to use it for a few change cases.

Spoiler
#==============================================================================
# ** Vocab
#------------------------------------------------------------------------------
# This module defines terms and messages. It defines some data as constant
# variables. Terms in the database are obtained from $data_system.
#==============================================================================

module Vocab

# Écran d'un magasin
ShopBuy = "Acheter"
ShopSell = "Vendre"
ShopCancel = "Annuler"
Possession = "En possession"

# Écran de statut
ExpTotal = "Exp. totale accumulée :"
ExpNext = "%s suivant dans ..."

# Écran de sauvegarde et chargement
SaveMessage = "Sauvegarder dans quel fichier ?"
LoadMessage = "Charger quelle partie ?"
File = "Fichier"

# Affiché quand il y a plusieurs membres dans l'équipe
PartyName = "L\'équipe à %s"

# Messages de combat généraux
Emerge = "%s apparaît !"
Preemptive = "%s a pris l'avantage !"
Surprise = "%s s'est fait surprendre !"
EscapeStart = "%s fuit !"
EscapeFailure = "La tentative de fuite a échoué !"

# Messages de fin de combat
Victory = "%s a gagné !"
Defeat = "%s s\'est pris une branlée !"
ObtainExp = "%s points d'expérience reçus !"
ObtainGold = "%s\\G trouvés !"
ObtainItem = "%s trouvé !"
LevelUp = "%s est maintenant %s %s !"
ObtainSkill = "%s appris !"

# Message affiché lors de l'utilisation d'un objet
UseItem = "%s utilise %s !"

# Coup critique
CriticalToEnemy = "Un joli coup !"
CriticalToActor = "Un coup douloureux !"

# Résultats des actions sur les personnages
ActorDamage = "%s a reçu %s dégâts !"
ActorRecovery = "%s a récupéré %s %s !"
ActorGain = "%s gagne %s %s !"
ActorLoss = "%s perd %s %s !"
ActorDrain = "%s a été drainé de %s %s !"
ActorNoDamage = "%s n'a rien senti !"
ActorNoHit = "Raté ! %s n'a pris aucun dégât !"

# Résultats des actions sur les ennemis
EnemyDamage = "%s a reçu %s dégâts !"
EnemyRecovery = "%s a récupéré %s %s !"
EnemyGain = "%s gagne %s %s !"
EnemyLoss = "%s perd %s %s !"
EnemyDrain = "Drain de %s %s de %s !"
EnemyNoDamage = "%s n'a rien senti !"
EnemyNoHit = "Raté ! %s n'a pris aucun dégât !"

# Esquive et contre-attaques
Evasion = "%s a esquivé l'attaque !"
MagicEvasion = "%s a contré la magie !"
MagicReflection = "%s a renvoyé la magie !"
CounterAttack = "%s contre-attaque !"
Substitute = "%s protège %s !"

# Renforcements et affaiblissements
BuffAdd = "%2$s de %1$s augmente !"
DebuffAdd = "%2$s de %1$s diminue !"
BuffRemove = "%2$s de %1$s est revenu à la normale."

# Compétence ou objet qui n'a aucun effet
ActionFailure = "Aucun effet sur %s !"

# Message d'erreur
PlayerPosError = "La position de départ de l'équipe n'est pas définie."
EventOverflow = "Nombre maximum d'appels d'évènement commun atteint."

# Caractéristiques
def self.basic(basic_id)
$data_system.terms.basic[basic_id]
end

# Stats
def self.param(param_id)
$data_system.terms.params[param_id]
end

# Types d'équipements
def self.etype(etype_id)
$data_system.terms.etypes[etype_id]
end

# Commandes
def self.command(command_id)
$data_system.terms.commands[command_id]
end

# Unité monétaire
def self.currency_unit
$data_system.currency_unit
end

#--------------------------------------------------------------------------
def self.level; basic(0); end # Niveau
def self.level_a; basic(1); end # Niveau (abrégé
def self.hp; basic(2); end # PV
def self.hp_a; basic(3); end # PV (abrégé)
def self.mp; basic(4); end # PM
def self.mp_a; basic(5); end # PM (abrégé)
def self.tp; basic(6); end # PT
def self.tp_a; basic(7); end # PT (abrégé)
def self.fight; command(0); end # Combattre
def self.escape; command(1); end # Fuir
def self.attack; command(2); end # Attaquer
def self.guard; command(3); end # Se défendre
def self.item; command(4); end # Objets
def self.skill; command(5); end # Compétences
def self.equip; command(6); end # Équipement
def self.status; command(7); end # Statut
def self.formation; command(8); end # Formation
def self.save; command(9); end # Sauvegarder
def self.game_end; command(10); end # Quitter le jeu
def self.weapon; command(12); end # Armes
def self.armor; command(13); end # Armures
def self.key_item; command(14); end # Objets clés
def self.equip2; command(15); end # Changer équip.
def self.optimize; command(16); end # Optimiser
def self.clear; command(17); end # Tout enlever
def self.new_game; command(18); end # Nouvelle partie
def self.continue; command(19); end # Charger partie
def self.shutdown; command(20); end # Quitter
def self.to_title; command(21); end # Écran titre
def self.cancel; command(22); end # Annuler
#--------------------------------------------------------------------------
end


Thanks in advance !
Code:
ShopBuy         = $game_switches[n] ? "Buy" : "Acheter"
Thank you, but ... the game not starting


Undefined method [] nil:Nilblabla
Code:
ShopBuy         = ($game_switches && $game_switches[n]) ? "Buy" : "Acheter"
Whatever I turn the $game_switches[10] ON or OFF, only the second result is shown. "Acheter"


I  reversed "Buy" : "Acheter" /  "Acheter" : "Buy"  to confirme that.
🙁   It looks like it's defining constants as the game is loaded, not looking them up at runtime.


You would have to have the script rewritten so it defines them as methods instead of constants.  For example, replace that whole ShopBuy line (comment the existing one out, don't actually delete it) with this:

Code:
def self.ShopBuy
  $game_switches[n] ? "Buy" : "Acheter"
end



however, I'm not sure even that will work, as I don't know if method names in RGSSx can start with a capital letter.


If it works, you can just do that with all the ones you want to change.
And of course, it do not working. I tried my self to find out guessing and guessing again (I dont know anything about scripting).


whatever I do yours or the one I tried :

Spoiler
def self.vocab_ShopBuy
if $game_switches[10]= true
vocab.ShopBuy = "Buy"
else
vocab.ShopBuy = "Acheter"
end
end

The result is the same, error directed to Window_ShopCommand at line 32

Spoiler
#==============================================================================
# ** Window_ShopCommand
#------------------------------------------------------------------------------
# This window is for selecting buy/sell on the shop screen.
#==============================================================================

class Window_ShopCommand < Window_HorzCommand
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(window_width, purchase_only)
@window_width = window_width
@purchase_only = purchase_only
super(0, 0)
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
@window_width
end
#--------------------------------------------------------------------------
# * Get Digit Count
#--------------------------------------------------------------------------
def col_max
return 3
end
#--------------------------------------------------------------------------
# * Create Command List
#--------------------------------------------------------------------------
def make_command_list
add_command(Vocab::ShopBuy, :buy)
add_command(Vocab::ShopSell, :sell, !@purchase_only)
add_command(Vocab::ShopCancel, :cancel)
end
end

well ...


Thank you anyway !
yeah, I don't think you're going to get it without changing every other script that refers to it.  Messy 🙁
Yes, module constants are evaluated only once on startup, and they will never be refreshed during the game, hence the name "constants".


Also, module constants are evaluated before anything else (before any module/class method would run), so, before $game_switches is created.


It's not really messy to change it, but it is certainly tedious.


For example:

Spoiler
Code:
module Vocab
#~   ShopBuy         = "Buy"
#~   ShopSell        = "Sell"
#~   ShopCancel      = "Cancel"
#~   Possession      = "Possession"

  def self.ShopBuy
    return $game_switches[24] ? "Purchase" : "Buy"
  end
  def self.ShopSell
    return $game_switches[24] ? "Offer" : "Sell"
  end
  def self.ShopCancel
    return $game_switches[24] ? "Exit" : "Cancel"
  end
  def self.Possession
    return $game_switches[24] ? "Owned" : "Possession"
  end

end

class Window_ShopCommand < Window_HorzCommand

  def make_command_list
    add_command(Vocab.ShopBuy,    :buy)
    add_command(Vocab.ShopSell,   :sell,   !@purchase_only)
    add_command(Vocab.ShopCancel, :cancel)
  end

end



Commenting out the constants is optional, I just don't like useless code anywhere. 😛


Just make a method in the module, use the same name as the constant used (this part is optional as well, use any names you want, but you will have to change the name in the code that refers the constant as well than), and change the double : signs to single dots where the constant is called, and it will work.


While it is certainly not encouraged to use capital letters for method names (it could clash with a module name in some cases, for example), it is still allowed. I recommend that you change them to lowercase letters, because you will have to edit the places where the default constants are called anyway, so while you are doing that, a little extra copy/paste job shouldn't be hard to do.


Just make sure that you don't use any checks which can not be executed when your method is called within your new methods or your game will crash.


Also, while the title screen can execute $game_switches checks, all of those checks will return false, because $game_switches is just initialized on the title screen, but no actual file is loaded to get the real values from it, nor could it decide which file to read the "correct" values from, so using that check on the title screen vocabulary is kinda pointless.


Note that a lot of the default vocab actually uses a method to get the correct text. You can directly add conditional checks for those, that will work without errors. 


And some vocab texts are not even defined in the default Vocab text (such as element names, for example), so if you want to add a condition for those too, you will have to find out their method name to do so, and you will also have to find out where these methods are called. These vocab things are not displayed anywhere in the default menus, so I guess, that is why they never added them into the Vocab module.
Thank you Sixth.


It works perfectely for shops, but I quess it's impossible to do it for battle : Attack, Skills, magic, ..., ...  cause they are not in vocab, right?


Plus, if I try to do it the same way with :


  EscapeStart     = "%s Blabla"
  EscapeFailure   = "Blaaa Blabla!"


It messes up with others scripts I'am using.


Whatever I use turn ON/OFF :


def self.Defeat
return $game_switches[24] ? "Aaarrgg !" : "Ouch !"
end


The result stays exactely the one as the original Vocab.


I guess the shop works because I dont have any scripts whitch interact/change the ShopStuff ...


I have to comfes that I have pain to understand what the : does or the single . does and checks and ..., ..., ...
The double : sign is used to get a constant from a module or to get inside nested modules/classes. It can also be used to call module methods, unless... the method name starts with a capital letter... This is one of the reasons why it is discouraged to use capital letters for your method names.


The single . sign is used to call methods on objects (objects can be classes or modules as well). This can NOT get module constants, but it can call methods with capital letters.


For further clarification...


The things like self.method_name_here are methods, while the things like ConstantNameHere = some_data_here are constants in modules.


If you use other scripts which rewrite part of the vocab or use them at other places, you will have to change all of them in those scripts too.


I suppose this is why some of your modifications won't apply, some other scripts may not even use the default vocabulary for their text displays, or they directly call the vocab constants at other places (an you will have to edit these places too if they do).


The Attack, Skills, etc command names are part of the Vocab module too. Like I mentioned, some parts of the vocab are already using methods to get the correct text, and these commands got a method too. They can be found at the bottom of the Vocab module. Changing these is easier, because they are already inside a method, so you don't have to edit anything else in any other script, just add your conditions in their methods and they should work.


If you use a lot of custom scripts displaying these vocab texts, it might be better to just edit the displayed text directly in these scripts, or even better, make your own vocab module and replace the texts with those. That's what I do in my projects usually if I need to display the same texts at different places, so that I can simply edit it at one place, and they all change at the same time. Although this may not help much if you are not script savvy enough to do it, but there is always time to learn something new, right? 😛
Thanks a lot Sixth !


It works well at the moment for the few stuffs I need.


I wish to know everything, but I cant. ... anyway I try to remember as more as possible.


And little by little, I start to understant what append if I touch this or that.
Hi !

I've got troubles about a script-editing that is very close to what you were talking about.
I know merely nothing about scripting so I'm begging for your help ^^
I needed to be able to switch the menu language of my project and the informations you gave here permitted me to accomplish that with
all that I wanted except for the 5 equip_slot names (by default : "weapon", "shield" ...)

In other words, I want the menu language to change according to the switch's position (number 100 on my screenshot).

What are the lines I'd have to write ? And where ? I tried many things but none worked.

explanation1.jpg
Problem solved !

script edit for translating equip slot names.jpg

Original thread: https://forums.rpgmakerweb.com/threads/vocab-script-editor-insert-condition-switches.71495/