Module change via Custom Name?

Hello everyone!
well first off i mean i have been using a very interesting script called "External Script Loader" which allows RPG Maker to load .rb script externally (as file)

the matter is the following.
I create an external file with a Module
Example:

Ruby:
module Vocab_2
Item_1 = "Bow"
end

RPG Maker loads it perfectly. but I wanted to experiment further.
in Window_Base / def draw_item_name
I wanted to see if the item name could define the module.
Example:

Write here:
0004.png

equals Item.name
0002.png


but I would like the item to have the name of the module Vocab_2 Item_1 to define its name (in this case "Bow")
so i did the following:
0003.png

in this case item.name is equals Item_1

but for some reason it doesn't work.
I would appreciate if someone told me how to make the item name in the program define the module to display the name.
can that be possible?

Anyway, I would like to see if this technique also works not only with the names of the items, but also with $game_message.all_text and/or item.description.
thanks to everyone beforehand.
It doesnt work because Vocab_2:: + item.name would actually mean

Get the text equivalent of Vocab_2:: then add item.name to that text

It doesnt become a call to Vocab_2::Item_1

You can try to replace it with this, see if it works

eval("Vocab_2::" + item.name)

This should be adding the words first, before evaluating them as a ruby expression via the eval call. Though I dont suggest this since your rb file is external, if the player inputs a malicious ruby code as an item name, the eval will run that malicious code.

another possibility is doing it via a hash

Code:
module Vocab_2
TEXTS = {}
TEXTS["Item_1"] = "Bow"

Then on your draw_item_name, just do

Vocab_2::TEXTS[item.name]
It doesnt work because Vocab_2:: + item.name would actually mean

Get the text equivalent of Vocab_2:: then add item.name to that text

It doesnt become a call to Vocab_2::Item_1

You can try to replace it with this, see if it works

eval("Vocab_2::" + item.name)

This should be adding the words first, before evaluating them as a ruby expression via the eval call. Though I dont suggest this since your rb file is external, if the player inputs a malicious ruby code as an item name, the eval will run that malicious code.

another possibility is doing it via a hash

Code:
module Vocab_2
TEXTS = {}
TEXTS["Item_1"] = "Bow"

Then on your draw_item_name, just do

Vocab_2::TEXTS[item.name]
Yes, it works, but does this method still work for text windows?
I mean, it has the same defined text that can be defined with a module.
as:
Window_Message
0005.png


Could I still function like this the way you say?
How to get new version
Yes, it works, but does this method still work for text windows?
I mean, it has the same defined text that can be defined with a module.
as:
Window_Message
View attachment 140162

Could I still function like this the way you say?

It should work for any thing that shows text... Or even other data types actually, as long as you're returning the correct data type.
It should work for any thing that shows text... Or even other data types actually, as long as you're returning the correct data type.
I have tried it with the same formula, but the window does not show any text.
What formula did you use? and what does your module look like right now? What is the text you wrote in your message box?

One problem I can think of though is that the text in the message box isnt actually coded directly as how you typed it because the engine adds some formatting stuff to it (like adding line breaks etc which is then handled by this process_text method). This would also mean that you need to know how the engine formats them so that your texts in the module would also follow the format to avoid problems in showing the text.
What formula did you use? and what does your module look like right now?
0007.png

0008.png

it is assumed that if a text window that has the word "Diag_1" it should show the vocab_2 / MGS module word that says "Text of text"

but when you try it in the game it doesn't show any text.
View attachment 140169
View attachment 140170
it is assumed that if a text window that has the word "Diag_1" it should show the vocab_2 / MGS module word that says "Text of text"

but when you try it in the game it doesn't show any text.


Add this line above above the convert call:

p $game_message.all_text

Then test it with the console running, this should print out the how the engine sees the current text in your message box into the console.

Also, are you editing the default scripts directly? That is not suggested because once you have problems, it will be harder to determine the original state of the scripts (you'd need to open a new project to check). Also, that means that if you have another script (placed below Materials) that overwrites that method, your edits will not work.
there is no need to worry, I take into account all the actions I do.

here is the console:

mmmm .. for some reason the window added /n to the end of the text. I think that is the problem.
Add this line above above the convert call:

p $game_message.all_text

Then test it with the console running, this should print out the how the engine sees the current text in your message box into the console.

Also, are you editing the default scripts directly? That is not suggested because once you have problems, it will be harder to determine the original state of the scripts (you'd need to open a new project to check). Also, that means that if you have another script (placed below Materials) that overwrites that method, your edits will not work.
ready, I fixed it c:
I added the /n in the module

MGS = {}
MGS ["Diag_1\n"] = "Test"

and it works, thank you very much!
there is no need to worry, I take into account all the actions I do.

here is the console:

mmmm .. for some reason the window added /n to the end of the text. I think that is the problem.


Yeah, as I said in one of the replies before, the game adds formatting codes to the message box text because that's how the game knows what to do (like line breaks to determine where the next line begins because the message box can have four lines but the text you write is only taken as 1 whole text). Aside from the message box, this might also be the case at least for the description boxes, not sure though..

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/module-change-via-custom-name.120334/