(RMMV) How to put line breaks in a variable string?

Discussion in 'RPG Maker MV' started by Michael Primo, May 25, 2017.

  1. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hello guys,

    My problem is this:

    I want to use a plugin called RS_InputDialog by Biud436 for writing a 160 character string and show in a message.

    The problem is this: the 160 character string is too huge for the window and I can't disable wordwrapping on variables!

    What must I do?

    Thanks for your time,

    Michael Primo
     
    #1
  2. Trihan

    Trihan Speedy Scripter Veteran

    Messages:
    1,416
    Likes Received:
    926
    Location:
    Buckie, Scotland
    First Language:
    English
    Add a "\n".
     
    #2
    Michael Primo likes this.
  3. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hello!

    I tried that,but it only works if I put some text on the message window. I need the line breaks inside the string or other things I don't know because firstly stamp the variable and after the \n. I used \v[1]\n on the message box but it doesn't work,it only show the fully variable wordwrapped.

    Thanks!
     
    #3
  4. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Have you tried to add two "\" instead of one?
    Ex. "\\n"
     
    #4
    Michael Primo likes this.
  5. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hello! I tried \v[1]\\n \\n
    \v[1]\\n
    \v[1] \\n

    and it didn't work unfortunately... :(
     
    #5
  6. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Oh, I misunderstood the question, then. Mmm... Well the simple \n, I think, change line for all the placed text in the var. Have you tried to add the \n in the var itself? I mean, in the text storedin var. Or you probably need a way to calculate the the text height in relation to the window width.
     
    #6
    Michael Primo likes this.
  7. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Howdy!

    I tried even that.

    About the \n inside the string I Need to do automatically instead manually because when a person insert the 160 character he do all in-game so I mustn't edit later the string,because I won't make that string.

    About the text width I can do that thanks to the plugin,but I can show 70 characters per line,80 if thanks to YEP Message Core I reduce the font size.

    With the actually plugin (Biud436's RS_InputDialog) I can write only a large line.

    I tried even the Mr Trivel solution but It seems which I can do only a Short line,without making new lines.

    Alternative Question: what plugin can allow the user to input text,store in different variables and with multiple lines to edit (like the default 4 of the window)?

    Thanks for your time!
     
    #7
  8. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Well, I don't know if there is a plugin like that out here. I know the one made by biud and If a remember correctly Quxios has made something related to the input. Probably a way to solve this is to write a function that loop the text inserted by the user an when the text width is higher than the window width, push a line break in there.
     
    #8
    Michael Primo likes this.
  9. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    I wanted to try the Quxios solution but I saw 404 in Github and the quasixi.com site closed,so...I don't know how can I find the plugin.

    I thought a replace solution with a script After inserting the line,but maybe I was doing mistakes in doing It.

    Can you show me a Example?

    Thanks so much!
     
    #9
  10. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Have you tried to find him on github?
    About an example, you can try to add something like that, but should be tested and implemented on the correct place, I think you should add this feature in the plugin itself:
    Code:
    Example.prototype.textWrap = function() {
            var input = $gameVariables._data[BIUDSTOREDVAR];
            var text = input.replace(/(\r\n|\n|\r)/gm, "").split(' ').map(function(space) { return space.trim(); });
            var newText = '';
            var lw = 0;
            for(var i = 0; i < text.length; i++) {
                lw += i == 0 ? this.textWidth(text[i]) : this.textWidth(' ' + text[i]);
                if(lw >= WINDOWWIDTH) {
                    newText += i == 0 ? text[i] : '\n' + text[i];
                    lw = 0;
                }
                else newText += i == 0 ? text[i] : ' ' + text[i];
            }
            return newText;
        };
    This an example how I would write a text wrap code, but depends on the situation itself.
     
    #10
    Michael Primo likes this.
  11. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Thanks so much! I'll try it today! ^_^
     
    #11
  12. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hello!

    I tried to insert the snippet in this way.


    it doesn't work.

    I tried to go on Quxios Github but I doesn't see the repo of Quasi Input,it seems he deleted it. I don't know.

    Thanks for your time!
     
    #12
  13. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Try this way, before the Input Clear and under the if statment on line 518, add this one to reset the var like that:
    Code:
    $gameVariables.setValue(RS.InputDialog.Params.variableID, this.textWrap())
     
    #13
    Michael Primo likes this.
  14. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    [​IMG]

    I tried to insert the things in this way,

    I have a TypeError: undefined is not a function.

    For this attempts I am using the demo of RS_InputDialog so I don't think is a problem of my game or a script I inserted.

    Thank you for your support and your fast reply!
     
    #14
  15. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Oh the problem is about the text width. I didn't notice you have inserted in a Scene. The error is related to the fact that in Scene_InputDialog and in its constructor there is not the text width function that is inserted in the windows classes. Probably, you can try to proceed this way, add this code:

    Code:
    Scene_InputDialog.prototype.createDummy = function() {
    this._dummyWindow = new Window_Base(0 ,0, 0, 0);
    this.addWindow(this._dummyWindow);
    }
    Add to the create method of the Scene_InputDialog the function i have write as: "this.createDummy())"
    Next, change the this.textWidth() to this._dummyWindow.textWidth()
     
    #15
    Michael Primo likes this.
  16. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    [​IMG]

    I inserted it in this way,but...it doesn't show the input dialog,and even if I manually insert the variable string the word wrap from the script doesn't work.

    Sorry if I am consuming your time...
     
    #16
  17. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    No problem, we're to help ;)
    You have misunderstood my words :)
    the create dummy should be inserted in the Scene_InputDialog.prototype.create, not in the okResult.
    In the ok result you should replace the set value for the variable: $gameVariables etc..
     
    #17
    Michael Primo likes this.
  18. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV
    I tried to put the this.createDummy(); on the first line of the Scene_InputDialog.prototype.textWrap function.

    Now I have a TypeError: Cannot read property "AddChild" of undefined. I don't know why.

    Thanks!
     
    #18
  19. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    335
    Likes Received:
    407
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Try to change the constructor of the scene from Scene_Base to Scene_MenuBase :)
     
    #19
    Michael Primo likes this.
  20. Michael Primo

    Michael Primo Villager Member

    Messages:
    17
    Likes Received:
    10
    First Language:
    Italian
    Primarily Uses:
    RMMV

    It works,but the word wrap not.

    I don't know why... :(

    Sorry...
     
    #20

Share This Page