railcat

Warper
Member
Joined
Jun 5, 2021
Messages
4
Reaction score
0
First Language
Bahasa
Primarily Uses
RMMV
hello there.
i have been searching forum but didn't get what i need (or i have no idea what i looking for)

i'am new in coding, i need help on making my own simple quest window. which now result in error.
TypeError text.replace is not function

Capture-copy.jpg

JavaScript:
(function() {  
    var _Scene_Menu_create = Scene_Menu.prototype.create;
    Scene_Menu.prototype.create = function() {
        _Scene_Menu_create.call(this);
        this._statusWindow.x = 0;
        this._statusWindow.y = 0;
        this._commandWindow.x = this._statusWindow.width;
        this._goldWindow.x = 0;
        this.createQuestWindow();
    };
    Window_MenuCommand.prototype.maxCols = function() {
        return 1;
    };
    Window_MenuCommand.prototype.numVisibleRows = function() {
        return 8;
    };
    Window_MenuStatus.prototype.windowWidth = function() {
        return Graphics.boxWidth / 4;
    };
    Window_MenuStatus.prototype.windowHeight = function() {
        var h1 = this.fittingHeight(1);
        var h2 = this.fittingHeight(2);
        return Graphics.boxHeight - h1 - h2;
    };
    Window_MenuStatus.prototype.maxCols = function() {
        return 1;
    };
    Window_MenuStatus.prototype.numVisibleRows = function() {
        return 1;
    };
    Window_MenuStatus.prototype.setActor = function(actor) {
        if (this._actor !== actor) {
            this._actor = actor;
            this.refresh();
        }
    };
    Window_MenuStatus.prototype.drawItemImage = function(index) {
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        var w = Math.min(rect.width, 144);
        var h = Math.min(rect.height, 144);
        var lineHeight = this.lineHeight();
        this.changePaintOpacity(actor.isBattleMember());
        this.drawActorFace(actor, rect.x, rect.y + lineHeight * 2.5, w, h);
        this.changePaintOpacity(true);
    };
    Window_MenuStatus.prototype.drawItemStatus = function(index) {
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        var x = rect.x;
        var y = rect.y;
        var width = rect.width;
        var bottom = y + rect.height;
        var lineHeight = this.lineHeight();
        this.drawActorName(actor, x, y + lineHeight * 0, width);
        this.drawActorLevel(actor, x, y + lineHeight * 1, width);
        this.drawActorHp(actor, x, y + lineHeight * 7, width);
        this.drawActorMp(actor, x, y + lineHeight * 8, width);
        this.drawActorIcons(actor, x, bottom - lineHeight * 1, width);
    };
    var _Window_MenuActor_initialize = Window_MenuActor.prototype.initialize;
    Window_MenuActor.prototype.initialize = function() {
        _Window_MenuActor_initialize.call(this);
        this.y = this.fittingHeight(2);
    };
    Scene_Menu.prototype.createQuestWindow = function() {
        this._questWindow = new Window_Quest(0, 0);
        this._questWindow.width =  Graphics.boxWidth - (this._commandWindow.width + this._statusWindow.width);
        this._questWindow.height =  Graphics.boxHeight;
        this._questWindow.x = this._commandWindow.width + this._statusWindow.width;
        this._questWindow.y = 0;
        this.addWindow(this._questWindow);
    };
    function Window_Quest() {
        this.initialize.apply(this, arguments);
    }
   
    Window_Quest.prototype = Object.create(Window_Base.prototype);
    Window_Quest.prototype.constructor = Window_Quest;
   
    Window_Quest.prototype.initialize = function(x, y) {
        var width = this.windowWidth();
        var height = this.windowHeight();
        Window_Base.prototype.initialize.call(this, x, y, width, height);
        this.refresh();
    };
   
    Window_Quest.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };
   
    Window_Quest.prototype.windowHeight = function() {
        return Graphics.boxHeight;
    };
   
    Window_Quest.prototype.refresh = function() {
        var x = this.textPadding();
        var y = this.lineHeight();
        var width = this.contents.width - this.textPadding() * 2;
        this.contents.clear();
        this.drawTextEx("Quest Name", x, y * 0, width);
        this.drawTextEx(this.quest1(), x, y * 1, width);
        this.drawTextEx("Quest Description", x, y * 3, width);
        this.drawTextEx(this.quest2(), x, y * 4, width);
    };
   
    Window_Quest.prototype.quest1 = function() {
        if ($gameVariables.value(41))
            return $gameVariables.value(41);
        else
            return '???';
    };
    Window_Quest.prototype.quest2 = function() {
        if ($gameVariables.value(42))
            return $gameVariables.value(42);
        else
            return '???';
    };
    Window_Quest.prototype.open = function() {
        this.refresh();
        Window_Base.prototype.open.call(this);
    };
   

})();

JavaScript:
$gameVariables.setValue(42, ["First Text", "Second Text", "Third Text"]);

this is just fine if i put single text, but i want variable 42 to be an array and when i set it's went error.
i can view it just fine in message window using \v[N]. but when open menu to show on my quest window that error comes.

1. please help fix my code and teach me what should i do.
2. i want it to be shown in paragraph, not a single line text, how to do that?
3. i want it only show 3 line text and when i added 4th array, the 1st one gone so it will be shown
JavaScript:
Second Text
Third Text
Fourth Text

thanks for helping~
 
Last edited:

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
583
Reaction score
552
First Language
german
Primarily Uses
RMMZ
The RPG Maker Code is not designed to put Arrays in the "Variables," so you will get problems. The \V[n] command works for single values only; however, we can extend the code :) Make a Plugin and insert this;

Code:
(function(){
const alias = Window_Base.prototype.convertEscapeCharacters
Window_Base.prototype.convertEscapeCharacters = function(text) {
text = text.replace(/\x1bW\[(\d+, \d+)\]/gi, function() {
  return $gameVariables.value(parseInt(arguments[1]))[parseInt(arguments[2])]
})
alias.call(this, text)
})();
In the Message Box, please write \W[n,m] to get "Variable" n with index m. Write V when the Variable is a single value and W when it's an Array.

It may not work in the Maker when pressing F2, but it should work in the Game.

Please tell me if it works, I wrote this code blindly.
 
Last edited:

railcat

Warper
Member
Joined
Jun 5, 2021
Messages
4
Reaction score
0
First Language
Bahasa
Primarily Uses
RMMV
thanks for helping,
i still got the same error and \W[n, m] also not showing the content. when i put \W[42,2] it showing [42,2] instead of the array content.
the code give an error in visual studio,
Code:
'{' expected.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,744
Reaction score
8,519
First Language
German
Primarily Uses
RMMV
coming from the other direction, drawtextex requires a single text string, not an array of multiple strings. So if you store multiple strings into an array-variable, then you need to extract them one after another and give them a single text for each drawtextex command.

That is not changed by anything done to enable array-variables.

if you need more help, you should post your current code with the problem you have now, it is very difficult to guess what you changed before an error happens.
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
583
Reaction score
552
First Language
german
Primarily Uses
RMMZ
thanks for helping,
i still got the same error and \W[n, m] also not showing the content. when i put \W[42,2] it showing [42,2] instead of the array content.
the code give an error in visual studio,
Code:
'{' expected.
I updated my last Post, please try again. And also check what Andar wrote.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,757
Reaction score
2,851
First Language
English
Primarily Uses
RMMZ
thanks for helping,
i still got the same error and \W[n, m] also not showing the content. when i put \W[42,2] it showing [42,2] instead of the array content.
the code give an error in visual studio,
Code:
'{' expected.

It's because Aerosys opened one more closure than he closed (it needs an extra } before the last bracket).
 

railcat

Warper
Member
Joined
Jun 5, 2021
Messages
4
Reaction score
0
First Language
Bahasa
Primarily Uses
RMMV
i have edited my first post. i put my full code there, also include picture now and explained how its going to.:rhappy:

I updated my last Post, please try again. And also check what Andar wrote.
i tried that one but still not worked, new error coming
TypeError Cannot read property 'slice' of undefined

my variable 41 is showing just fine because only single text stored to variable.
i want variable 42 to be able to show 3 line of text there.
i've read Andar post, and i wonder how to make it so can listed all array stored from the plugin side?

if can't be done i will turn around and maybe just put variable 42, 43, & 44 for that one.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,744
Reaction score
8,519
First Language
German
Primarily Uses
RMMV
i've read Andar post, and i wonder how to make it so can listed all array stored from the plugin side?
you can't.
you'll need one drawtextex command for each element of the array, the command CANNOT handle multiple strings.
so basically you'll need to count how many elements are in that array, then make a loop over that number and have one drawtextex for each element inside the array.
 

railcat

Warper
Member
Joined
Jun 5, 2021
Messages
4
Reaction score
0
First Language
Bahasa
Primarily Uses
RMMV
problem solved.
it's truly need to think hard about how to do it since the variable keep get into single line instead of being array. i can only pull index[0] because all stored there.
now i had it separate and like Andar said, i make a loop over the index to display each element inside array.

thanks for everyone whose helping me~
 

Zakarijah

I love making maps!
Veteran
Joined
Aug 18, 2019
Messages
183
Reaction score
23
First Language
English
Primarily Uses
RMMV
The RPG Maker Code is not designed to put Arrays in the "Variables," so you will get problems. The \V[n] command works for single values only; however, we can extend the code :) Make a Plugin and insert this;

Code:
(function(){
const alias = Window_Base.prototype.convertEscapeCharacters
Window_Base.prototype.convertEscapeCharacters = function(text) {
text = text.replace(/\x1bW\[(\d+, \d+)\]/gi, function() {
  return $gameVariables.value(parseInt(arguments[1]))[parseInt(arguments[2])]
})
alias.call(this, text)
})();
In the Message Box, please write \W[n,m] to get "Variable" n with index m. Write V when the Variable is a single value and W when it's an Array.

It may not work in the Maker when pressing F2, but it should work in the Game.

Please tell me if it works, I wrote this code blindly.
I'm having the same thing happen to me where I'm just trying to show the amount of an item obtaine but in the message box for the event it just says "Obtained [[21,22]"
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
583
Reaction score
552
First Language
german
Primarily Uses
RMMZ
@Zakarijah Yes, I think my regular expression is just bad, but I'm really not good at regular expressions. You can do some research about regular expressions and then try it yourself, or maybe another community member can help here.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,757
Reaction score
2,851
First Language
English
Primarily Uses
RMMZ
I think you just need to enclose each \d+ in brackets to make it its own capture group.

JavaScript:
(function(){
  const alias = Window_Base.prototype.convertEscapeCharacters
  Window_Base.prototype.convertEscapeCharacters = function(text) {
    text = text.replace(/\\W\[(\d+), (\d+)\]/gi, function() {
      return $gameVariables.value(parseInt(arguments[1]))[parseInt(arguments[2])]
  })
  alias.call(this, text)
})();
 
Last edited:

Zakarijah

I love making maps!
Veteran
Joined
Aug 18, 2019
Messages
183
Reaction score
23
First Language
English
Primarily Uses
RMMV
I think you just need to enclose each \d+ in brackets to make it its own capture group.

JavaScript:
(function(){
  const alias = Window_Base.prototype.convertEscapeCharacters
  Window_Base.prototype.convertEscapeCharacters = function(text) {
    text = text.replace(/\\W\[(\d+), (\d+)\]/gi, function() {
      return $gameVariables.value(parseInt(arguments[1]))[parseInt(arguments[2])]
  })
  alias.call(this, text)
})();
I updated the javascript to match this and saved it but it still says "Obtained [21,22]"

Is there a piece I'm missing?

I'm also not actually gaining the items anymore, either.

I'm a newbie though, so I'm sure I'm doing something wrong...?
 

Attachments

  • Salvaging 01.png
    Salvaging 01.png
    217.1 KB · Views: 6
  • Salvaging 02.png
    Salvaging 02.png
    169.2 KB · Views: 6

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,757
Reaction score
2,851
First Language
English
Primarily Uses
RMMZ
I updated the javascript to match this and saved it but it still says "Obtained [21,22]"

Is there a piece I'm missing?

I'm also not actually gaining the items anymore, either.

I'm a newbie though, so I'm sure I'm doing something wrong...?
I'll take a look when I have a sec.
 

Latest Threads

Latest Profile Posts

$Syringer.png
toying with a brand new monster design
Another doodle! Green-haired girl has no name yet, so, any suggestions?
She is about the same age as Nikki, and she is the last one of her clan, known for their innate skills in manipulating both ice and fire. She is a bit stubborn, as well as having a soft spot for kids.
Mystery messages from my AI assistant. :kaojoy:
1632842960834.png
Made some updates to a previous project I was working on. Trying to mimic the 16 bit Squaresoft aesthetic.

Forum statistics

Threads
115,434
Messages
1,089,893
Members
150,203
Latest member
mead80
Top