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:
index.php

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:
index.php

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

index.php


Third time pressing enter:

index.php

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

index.php



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

  • Screenshot (30).png
    Screenshot (30).png
    141.4 KB · Views: 34
  • Screenshot (36).png
    Screenshot (36).png
    135 KB · Views: 36
  • Screenshot (37).png
    Screenshot (37).png
    129.5 KB · Views: 36
  • Screenshot (38).png
    Screenshot (38).png
    136.3 KB · Views: 32
  • Screenshot (39).png
    Screenshot (39).png
    139.1 KB · Views: 35
  • Screenshot (40).png
    Screenshot (40).png
    133.5 KB · Views: 1

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,660
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,125
Reaction score
10,660
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]
 

Latest Threads

Latest Posts

Latest Profile Posts

image_2021-06-13_213812.png

Todays Lesson: Tiles are a pain to make xD
The game is not even 2% complete, but i just wanted to release something for funsies. :)
It's on my google drive.
It would be awesome if i could get a couple ideas and the like!
So yesterday Dad took me to Volcano Bay, and it was almost ruined by a thunderstorm... then it passed by and the lightning warning got lifted, leading to an awesome time sliding and swimming. Hopefully we get to go to the arcade tonight. The one we're planning on has a restaurant built in with AWESOME food. Not to mention how big the arcade itself is!
image_2021-06-13_150033.png

Maybe I'll actually try making a retro pack. Already have the shark fin made so why not xD
Hey everyone, for everybody following along with my RPG Maker MZ streams: There will unfortunately not be a stream tonight. There is a big exciting event that will go live next week that has been taking all my time, so look forward to that!

Forum statistics

Threads
112,200
Messages
1,066,531
Members
145,807
Latest member
wispy
Top