_interpreter.setWaitMode("message") doesn't work as expected

Discussion in 'Javascript/Plugin Support' started by ndruha, Jul 13, 2019.

  1. ndruha

    ndruha Warper Member

    Messages:
    2
    Likes Received:
    1
    First Language:
    ukrainian
    Primarily Uses:
    RMMV
    Hi. I'm new to RPG Maker MV, but experienced in game dev and programming. I would like to make my first game in RPG Maker to learn it. I tried to make a small game with visual event commands, and after succeeding, I'm now moving everything to Javascript, as I want to have my full game logic base in javascript only, in order to be unit-testable and portable to a different engine in future.

    My question today is about how I wait after the message appears on screen to do something else? In the event command it happens by itself, but it's not like that in javascript. Here is my event handler function, where I tried to wait:

    PHP:
    SceneLighthouse.prototype.exitEvent = function() {
        
    $gameMessage.add("<WordWrap>I don't have any reasons to exit my small cosy lonely place right now.");
        
    $gameMap._interpreter.setWaitMode("message");
        
    $gamePlayer.moveStraight(8);
    }
    I want to achieve that the character move up only after the dialog box disappears. However, she moves up right together with the message appearance on the screen. What am I doing wrong here? RPG maker version is 1.6.2.

    The second question is about my way to workaround this, using setTimeout:

    PHP:
    SceneLighthouse.prototype.exitEvent = function() {
        
    $gameMessage.add("<WordWrap>I don't have any reasons to exit my small cosy lonely place right now.");
        
    this.wait(() => !$gameMessage.isBusy(), () => $gamePlayer.moveStraight(8));
    }
    So I'm waiting while the $gameMessage.isBusy() becomes false again.
    That works, where the wait function is simply this:

    PHP:
    SceneLighthouse.prototype.wait = function(predicatecallback) {
        
    setTimeout(() => {
            if (
    predicate() === true) {
                 
    callback();
            }
            else {
                
    this.wait(predicatecallback)
            }
        }, 
    100);
    }
    Is this way ok in RMMV, or is there any concernes? If this is ok, then I would rather use this general way for my waits for anything in the game to not mess with the engine specifics too much.
     
    Last edited: Jul 13, 2019
    #1
  2. caethyril

    caethyril ^_^ Veteran

    Messages:
    957
    Likes Received:
    596
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    This is expected behaviour. The interpreter is for converting event commands to code; your code says "add some text to $gameMessage, tell the interpreter to wait until the message is gone, and move the player up 1 tile". The moveStraight call does not pass through the interpreter, it is a method called there and then. If you're porting all your events to pure JavaScript, there's no need to retain the event interpreter~
     
    #2
    ndruha likes this.
  3. ndruha

    ndruha Warper Member

    Messages:
    2
    Likes Received:
    1
    First Language:
    ukrainian
    Primarily Uses:
    RMMV
    Thank you for clarification!
     
    #3
    caethyril likes this.

Share This Page