$gameScreen.fadeOut(), interpreter.wait(), and others not working.

Discussion in 'Learning Javascript' started by ndcomix, Oct 7, 2019.

  1. ndcomix

    ndcomix Villager Member

    Messages:
    6
    Likes Received:
    1
    Primarily Uses:
    N/A
    Hi there. I am experiencing issues with certain plugin commands executing in javascript. To isolate external factors, I created a brand new game with no plugins and wrote this simple code:

    Code:
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        if (command === "testFadeOut") {
            console.log('start test');
            $gameScreen.startFadeOut(30);
            this.wait(30);
            $gameScreen.startFadeIn(30);
            console.log('finish test');
        }
    };
    
    When I execute the plugin command, all that happens is the console logs each call immediately without delay and no screens are faded in or out. I have tried executing a variety of code with the interpreter's wait() function but it just does not work from within the javascript. What am I missing here? Is there some other approach that will allow these types of commands to work? And just in case you're wondering: yes, this code must execute from within javascript files and not the RMMV editor, event editor, etc.

    Thank you for your insight!
     
    #1
  2. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    871
    Likes Received:
    633
    First Language:
    English
    Primarily Uses:
    RMMV
    @ndcomix Actually, the screen fade and the wait functions do work, but perhaps not in the way that you might be expecting. The plugin command is executed all at once and does not stop when the 'wait' function is called. If you only call 'startFadeOut' and 'wait', the screen will fade out as normal. Technically you could have a function updating every millisecond and trigger when the 'waitCount' variable reaches zero :

    Code:
    if (command === "testFadeOut") {
        console.log('start test');
        $gameScreen.startFadeOut(30);
        this.wait(30);
    
        var interval = setInterval(() => {
          if (this._waitCount === 0) {
            console.log('finish test');
            $gameScreen.startFadeIn(30);
            this.wait(30);
            clearInterval(interval);
          }
        }, 1);
    }
    Not sure I would want to rely on that, though. Or you could have a 'while' loop that updates the game as wait timer counts down, I suppose. Does the fade in process have to happen in the same command?
     
    #2
  3. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,848
    Likes Received:
    7,666
    Location:
    Texas
    First Language:
    English
    Primarily Uses:
    RMMV

    I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #3
  4. ndcomix

    ndcomix Villager Member

    Messages:
    6
    Likes Received:
    1
    Primarily Uses:
    N/A
    Thanks for your input Ossra, I appreciate your time & suggestions. Unfortunately, there is a multitude of complex movements, animations, and screen effects that need to coordinate with the frames. Using a time interval was not effective in my tests, particularly with the quantity of effects. I suppose there may be a way to build out a large event page programmatically then assign it to my event and execute... was really hoping to avoid that route though. If you or anyone else has any other suggestions I'd love to hear them. Thanks again!
     
    Last edited: Oct 7, 2019
    #4
  5. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    871
    Likes Received:
    633
    First Language:
    English
    Primarily Uses:
    RMMV
    @ndcomix Do you have an example? A list of event commands that you want to occur in a certain way? There are methods to more or less force event commands to wait for one another.
     
    #5
  6. ndcomix

    ndcomix Villager Member

    Messages:
    6
    Likes Received:
    1
    Primarily Uses:
    N/A
    Here's a little context: I've built a puzzle game where the player can arrange all sorts of components and characters to "set" a level however they'd like. Afterwords, they hit "go" and the program runs through the level, causing certain interactions and reactions based on the player's setup. Most of these interactions/combinations should be tied to specific animations. Given the multitude of components (particularly as the game progresses) the potential animation combinations number in the hundreds or maybe even thousands. That's why it has to be assimilated programmatically.

    One short example could be:

    Code:
    1. Party Leader moves backwards one step.
    2. Party Leader "attack animation" (Set Movement Route, "Wait")
    2.1 Change Party Leader Image
    2.2 Wait 3 frames
    2.3 Change Party Leader Image
    2.4 Wait 3 frames
    2.5 Change Party Leader Image
    2.6 Wait 3 frames
    2.7 Change Party Leader Image
    2.8 Wait 3 frames
    2.9 Change Party Leader Image
    2.10 Wait 3 frames
    2.11 Change Party Leader Image
    2.12 Wait 3 frames
    2.13 Change Party Leader Image
    2.14 Wait 3 frames
    2.15 Change Party Leader Image
    2.16 Wait 3 frames
    3. Party Leader "attack animation" (Set Movement Route)
    3.1 Change Party Leader Image
    3.2 Wait 3 frames
    3.3 Change Party Leader Image
    3.4 Wait 3 frames
    3.5 Change Party Leader Image
    3.6 Wait 3 frames
    3.7 Change Party Leader Image
    3.8 Wait 3 frames
    3.9 Change Party Leader Image
    3.10 Wait 3 frames
    3.11 Change Party Leader Image
    3.12 Wait 3 frames
    4. Show Animation "This Event" Hit, Thunder
    5. Flash Screen 255,255,255,170 10 frames "Wait"
    6. Flash Screen 255,255,255,170 10 frames "Wait"
    7. Flash Screen 255,255,255,170 10 frames
    8. Event A "attack animation" (Set Movement Route, "Wait")
    ... etc, etc, etc ..
    
     
    #6
  7. ndcomix

    ndcomix Villager Member

    Messages:
    6
    Likes Received:
    1
    Primarily Uses:
    N/A
    Oops, double posted. Plz disregard this comment. :) Or mods plz delete it!
     
    Last edited: Oct 7, 2019
    #7
  8. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    871
    Likes Received:
    633
    First Language:
    English
    Primarily Uses:
    RMMV
    @ndcomix Hmm, well, whenever I want to create a hard wait in order for a specific event command to complete before moving on to the next command, I use a loop and a conditional branch :

    Code:
    ◆Script:$gameScreen.startFadeIn(30);
    ◆Loop
      ◆If:Script:$gameScreen._brightness >= 255;
        ◆Break Loop
        ◆
      :End
      ◆Wait:1 frame
      ◆
    :Repeat Above
    
    The 'startFadeIn' function gradually raises the '_brightness' variable in '$gameScreen' up to a value of '255', so the loop will continue to hold the event until it reaches that amount. You can even have certain commands execute at a certain point within that loop, as well :

    Code:
    ◆Loop
      ◆If:Script:$gameScreen._brightness >= 120 && $gameScreen._brightness < 125;
        ◆Play SE:Attack3 (90, 100, 0)
        ◆Set Movement Route:Player (Wait)
        :                  :◇1 Step Backward
        :                  :◇1 Step Backward
        ◆
      :End
      ◆If:Script:$gameScreen._brightness === 0;
        ◆Break Loop
        ◆
      :End
      ◆Wait:1 frame
      ◆
    :Repeat Above
    
    If you are within a Movement Route command, you can use an 'if' in a Script Command to do something similar :

    Code:
    if ($gameMessage.isBusy()) { this._moveRouteIndex--; this._waitCount = 1; };
    When the above is encountered in a Movement Route, the event will wait until there is not a Show Text message on the screen.

    I am not sure if this is useful to you as I am not quite sure what the provided example is really doing, but I thought I would offer some options.
     
    #8
  9. ndcomix

    ndcomix Villager Member

    Messages:
    6
    Likes Received:
    1
    Primarily Uses:
    N/A
    I Ossra, I appreciate your input. Unfortunately, that's not going to be feasible approach for reasons that would take me a long time to explain but could probably be summarized as: 1) Too resource intensive and 2) Conflicting variables & validators between multiple simultaneous loops.

    I will continue to explore programmatically building an event page then executing it, though if there are any other suggestions out there I'd appreciate hearing them. Thank you!
     
    #9

Share This Page