trying to make text go backwards problem

nikhil

Villager
Member
Joined
Oct 20, 2016
Messages
6
Reaction score
0
First Language
English
Primarily Uses
Hello!!

I think this is my first actual post in this forums so.....that's fun ^^:

Anyway, I have a problem with some javascript that I've been working on. I'm still a bit of a newbie when it comes to this language so please bear with me.

So I'm trying to find a way to make it so that when the player presses a certain button, they can 'reverse' the text and go back to previous text boxes. It's kinda like in Phoenix Wright where in the testimonies you can go either backwards and forwards in text. Anyway, the code I wrote for trying to do this is here:

var Text = new Array;
var Recycling = new Array;
var part;
function showText() {
var textObject;
for(i = 0; i < Text.length; i++){
if(!$gameMessage.isBusy()){
textObject = Text;
$gameMessage.setFaceImage(textObject.faceImage, textObject.faceImageNumber);
$gameMessage.setBackground(textObject.background);
$gameMessage.setPositionType(textObject.position);
$gameMessage.add(textObject._text);
$gameMessage.newPage();
Text.splice(i,1);
}
}
}
function addToMessegeArray(index,contents){
if(Text.length < index + 1){
Text.push(contents);
Recycling.push(contents);
part = index;
}
}

function Backwards() {
if (part != 0)
part--;
Text.push(Recycling[part]);
showText();
}
var DV_Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
DV_Scene_Map_update.call(this);
if (Text.length>0) {
showText();
}
};
var Nik_Message_Update = Window_Message.prototype.update;
Window_Message.prototype.update = function() {
Nik_Message_Update.call(this);
if (Input.isTriggered('shift')){
Backwards();
}
}




Basically what I'm trying to do with this is make a list of text inside the text window and adding it using AddToMessageArray to simulate text. You can see it here:

That part is working fine. The part that's really tripping me up is the trying to go backwards part. According to the code, it should go back whenever I press 'shift'. The problem that I'm having is that it's not really going back correctly.


Here's what happens when I press enter for the first time:

Here's the text when I do it the second time:



Third time pressing enter:


Here's what happens when I press "Shift" at this moment:




It goes back one and displays the text. However, when I press shift again, nothing happens. I have to press enter again and then press shift afterwards in order to go fully back to 'hi'. Is there anyway I can just press shift and it'll go straight to the previous text? Thank you in advance for anyone and if I wasn't clear on anything, please tell me. Again, first time. Probably missed something ^^;
 

Attachments

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,039
Reaction score
10,259
First Language
Czech
Primarily Uses
RMMV
Naturally it gets back one test before showing a text, because that's what you told it to do.
Code:
function Backwards() {
if (part != 0)
part--;
Text.push(Recycling[part]);
showText();
}
I would say that the part--should be one line lower. Btw. if also uses curly brackets with the code.
Also, it does it like this, because $gameMessage uses a Wait type "message" when it is active, which means it won't do anything until you hit enter. You need to use either a custom window or edit the core functiobality.
 

nikhil

Villager
Member
Joined
Oct 20, 2016
Messages
6
Reaction score
0
First Language
English
Primarily Uses
Naturally it gets back one test before showing a text, because that's what you told it to do.
Code:
function Backwards() {
if (part != 0)
part--;
Text.push(Recycling[part]);
showText();
}
I would say that the part--should be one line lower. Btw. if also uses curly brackets with the code.
Also, it does it like this, because $gameMessage uses a Wait type "message" when it is active, which means it won't do anything until you hit enter. You need to use either a custom window or edit the core functiobality.


thanks for the help!! With that I was able to get like 90% done with this!! There's only one thing I'm having a bit of trouble with:

Here's the code I wrote that makes a custom window and adds text:

Code:
var Text = ['Hello' , 'hi' , 'idk'];
var part = 0;
(function() {
    var _Scene_Map_start = Scene_Map.prototype.start;
    Scene_Map.prototype.start = function() {
        _Scene_Map_start.call(this);
        this._myWindow = new myWindow(50,50);
        this.addWindow(this._myWindow);
    };
    var _Scene_Map_Update = Scene_Map.prototype.update;
    Scene_Map.prototype.update = function() {
        _Scene_Map_Update.call(this);
        if (Input.isTriggered('right')){
            part++;
            if (part == Text.length){
                $gameScreen.startFadeOut(24);
                part = 0;
                Game_Interpreter.prototype.wait(60);
                $gameScreen.startFadeIn(30);
            }
        }
        else if (Input.isTriggered('left')) {
            part--;
            if (part < 0){
                part = 0;
            }
        }
    };
    function myWindow(){
        this.initialize.apply(this,arguments);
    };
    myWindow.prototype = Object.create(Window_Base.prototype);
    myWindow.prototype.constructor = myWindow;
    myWindow.prototype.initialize = function(x,y){
        Window_Base.prototype.initialize.call(this,x,y,this.windowWidth(),this.windowHeight());
        this._value = -1;
        this.refresh();
    };
    myWindow.prototype.refresh = function() {
        if (this._value != part) {
            this._value = part;
            this.contents.clear();
            this.drawText(Text[this._value],0,30,this.windowWidth(),'left');
        }
    };
    myWindow.prototype.windowWidth = function(){
        return 300;
    };
    myWindow.prototype.windowHeight = function(){
        return 200;
    };
})();
The two biggest problems is that it only works when the function is self-executing. I wanted to have a little more control on when I can call this function, but it doesn't seem to work. Any tips on making me able to turn this on/off when I need to call it? The other sorta linked problem is that the text array has to be in the actual code. And you can't add anything or subtract anything in game. Anyway to make that work? Thanks in advance :3.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,039
Reaction score
10,259
First Language
Czech
Primarily Uses
RMMV
Before you call addWindow on that window, set its visible to false.

If you want more control, you need the scene map update function to handle everything in regards to that window (except for creation), because that is the function that gets fired every frame. So now set in the window a condition, which will if true show the window and show the text you want to show, if false, nothing happens.
e.g.
if (switch 1 is on)
window.refresh()
Text.pop()
visible = true;

And then edit the window's refresh function. Instead of this weirdness
this.drawText(Text[this._value]
(weirdness because -1 is not a valid argument in js for arrays. In python yes, but not in js.)
use this.drawText(Text[Text.length() - 1]
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Having lots of fun using different PS brushes to add a lil' texture to the floors and walls in my maps.
Setup a system to cull enemies that are too far from the player to matter, and to spawn new ones just outside of view. Take that lag! :LZSexcite:
That trope is alive more than ever, not so much elemental Crystal's but gathering magical objects or doing "task" to unlock this oddly specific thing is everywhere, I saw it saw it in the IT 2 remake, avengers and every season of supernatural
It's raining...in winter :")

Forum statistics

Threads
93,715
Messages
914,881
Members
123,318
Latest member
Hextasy
Top