[SOLVED] How to change displayed item name?

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
I'm attempting to write an unidentified items script, and this includes potentially changing the displayed names of unidentified items (and also other stuff like description, price, icon index, for example, eventually).


However, I'm having problems working out how to change the displayed name of an item, conditionally or at all. At first I thought I'd be able to override Game_Item.prototype.name with a function that under the right conditions returns a different name, but that doesn't seem to work.


What I have for conditionally replacing the name currently looks like this (without a check for whether it's identified, because right now I really just want this to work; without being able to conditionally change the displayed name, the rest is kind of pointless), and is probably stupid in at least one way:


Game_Item.prototype.name = function() {
if (this.meta.unidentified_name){
return this.meta.unidentified_name;
}
else {
return this.name;
}
};


With this, in-game dialogues, like the inventory or item select windows, still display the proper name of an item even when unidentified_name has been supplied in the item's note, and '$dataItems[1].meta.unidentified_name' returns the supplied alternate name for the item (because I'm lazy and test with potion).


Is this even the right place to be looking? Or am I on the right track, but doing something wrong?
 
Last edited by a moderator:

mjshi

Jack of Most Trades
Veteran
Joined
Feb 16, 2013
Messages
969
Reaction score
807
First Language
English
Primarily Uses
N/A
Well, what you're checking for is "unidentified_name", not "unidentified_item". Check your notetags.
 

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
That unfortunately is just a typo in the post (now corrected), not in the notetags. Item 1's notetags are as follows:


<unidentified_name:potion>


<unidentified_desc:A bottle of liquid.>


And, as I said, '$dataItems[1].meta.unidentified_name' does return the unidentified name properly.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I can't seem to find the original Game_Item.prototype.name function.. Maybe that has something to do with it? Like it doesn't exist so you can't overwrite it... That or the condition you supplied doesn't return true... Try putting a console error message before the return line when the condition is true then test with the debug console open to see if it reaches that part.


Also, won't this.name return a call to Game_Item.prototype.name, causing an infinite loop?
 
Last edited by a moderator:

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
That's possible, though I was reasonably sure in another script I was overriding a variable with a function with no issue, though I may be dumb and that might not be what I was actually doing. $dataItems[1].name does work, though, in this case, so it's not that the item doesn't have a name.


If I'm barking up the wrong tree, do you have any idea what I should be looking at to vary the displayed name?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I don't even see a .name variable on Game_Item too... It's actually puzzling me. XD or maybe it takes it directly from the database or something


btw, can you try to use this code instead just to see if the function and the conditions even run? change your code to this and run the game and open the debug console


Game_Item.prototype.name = function() {
//this is to check if the function even runs
console.error('notice','run');
if (this.meta.unidentified_name){
//this is to check if the condition returns true
console.error('notice','true');
return this.meta.unidentified_name;
}
else {
return this.name;
}
};




if the console will show run, it means your override works... if the console then says true, then it means the condition check also runs and is returning true... In that case it means the problem is elsewhere.


If the run message don't even show then we know for sure that the override doesn't work
 
Last edited by a moderator:

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
Well, it's more that items aren't really exposed in the code, in this case. The only reason I know items have a name is I can do console.log([item]) and that'll spit out the item's variables and functions to the console.


With your code, nothing new is making its way to the console. Guess it really isn't doing a thing.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
If it doesn't show a message when you view that item then it means your override isn't even running. So you need to find how they're actually finding the name of the items. My hunch right now is that they take it directly from the database items.


Yeah, seems like it's taking them directly from the database, which explains why Game_Item doesn't even have a name variable or function.. The functions in the game that shows the name of items etc actually uses the items from $dataItems rather than Game_Item. Seems like Game_Item is just there to provide a modifiable item object in-game and a link to the actual items in $dataItems.
 
Last edited by a moderator:

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
I'm not sure that's even going to be workable if I have to find and replace every single place they get the item name.


Hmm. Do you know where the inventory interface is in the code? So I can check there first?
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I wonder why they didn't do it like Game_Actors where they actually made a .name function... Maybe they never thought someone would try to change item names in-game.


I think everything that shows item names etc are in the rpg_windows.js or rpg_scenes.js


I think this line of code is of interest, here is where windows draw item's name, try this code that I edited for you


Window_Base.prototype.drawItemName = function(item, x, y, width) {
width = width || 312;
if (item) {
var iconBoxWidth = Window_Base._iconWidth + 4;
this.resetTextColor();
this.drawIcon(item.iconIndex, x + 2, y + 2);
if (item.meta.unidentified_name){
this.drawText(item.meta.unidentified_name, x + iconBoxWidth, y, width - iconBoxWidth);
}
else {
this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
}

}
};






PS: Tested it and it works... It showed watda on the item that I noted in the database with <unidentified_name:watda>


but how do you plan to be able to change it to identified mid-game?
 
Last edited by a moderator:

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
Instead of 'if (item.meta.unidentified_name)', I'd probably have something like the following:


if (item.meta.identified == "false" && item.meta.unidentified_name && [something indicating item hasn't been ID'd])


My original idea was to add an 'identified' boolean to items, but that didn't pan out. What I'm currently planning is each item that is picked up unidentified is indicated by a notetag (<identified:false> - there's also a default for whether items start identified or unidentified, so it may be useful for developers to say <identified:true>). I'm probably going to keep an array (or list, or dict, or whatever; I more frequently work with python) of items that have been identified, and check against that.


Then identifying an item becomes a matter of just writing a method that adds the item to the array/list/whatever on demand, and making sure that's used where appropriate (if I want to automatically identify a thing on usage, for example, needs to be somewhere in the usage code).


Edit:


Okay, I've tested it and it works. I've also been able to use this method to switch the item icon, and found where the item description was added, too. Thank you very much for your help.
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
glad to be of help, plus I learned a thing or two about MV from this. XD
 

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top