How to wait/pause until [...]

Discussion in 'Learning Javascript' started by Rink27, Nov 1, 2017.

  1. Rink27

    Rink27 Veteran Veteran

    Messages:
    222
    Likes Received:
    12
    Location:
    Caribbean
    First Language:
    English
    Primarily Uses:
    RMMV
    Hi. Is it possible for us to pause at a particular part in code until another condition becomes true?
    Or alternatively, prevent the playable character (and potentially other events) from moving until another condition becomes true?


    For example:

    > Text: Hello
    > Change Variable 2 = 10
    > Wait until [Shift] button is pressed
    > Text: Bye


    In the past I tried using a loop:

    *Loop
    > If: Button [Shift] is pressed down { do something }
    > If: Button [Cancel] is pressed down { Break Loop }
    *Repeat Above

    But it can be laggy and I don't think it's quite efficient.

    I also came across a setInterval method:
    Code:
    var wait = setInterval(click, 2000);
    
    function click() {
      console.log("Hi");
      if (TouchInput.isTriggered()) {
      clearTimeout(wait);
      }
    }
    but after it reaches the code above, it moves on to the next Event Command (while outputting "Hi" every 2 seconds until I click somewhere).

    What I am currently trying to achieve is to prompt the Player with "select where I should go", whereby the Player clicks somewhere on the map (via mouse or touch) and an event (the "I" from the message) - not the Player - moves to the coordinates of the click.

    I'm not sure of a good way to "pause" the game to await a particular input.
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,437
    Likes Received:
    6,488
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    Stopping player input or movement is not the same as pausing the game - and a simple loop is even worse than a wait.
    This might sound as a useless technical difference for people who aren't programmers, but it is a very important distinction and the reason why some of your tries didn't really work.

    There are several different ways to simulate something to the player depending on what exactly is needed.

    In your last case I wouldn't pause at but do something entirely different:
    Have events pretending to be the actors placed on their current position, disable follower display, change actor 1 sprites to the cursor.
    Then the player/cursor can go to the point selected, and you just have to remember to change the party back to normal at the coordinates you want.
    The player will never know that the cursor was bis party if it is done correctly
     
    #2
    Llareian likes this.
  3. Bex

    Bex Veteran Veteran

    Messages:
    1,264
    Likes Received:
    296
    First Language:
    German
    Primarily Uses:
    RMMV
    Its the Loop.
    If your Event is on Auto Run, than the Player cant move aslong as the Eventpage is executed.
    Than the Loop for the Button Input, but you need a 1Frame Wait, else you create an Endless Loop which would result in game crash.
    1Frame not more, else the button whill not be recogniced fluently.

    I believe other Events will continue there Autonomous Moveroute but iam not sure.
     
    #3
  4. Rink27

    Rink27 Veteran Veteran

    Messages:
    222
    Likes Received:
    12
    Location:
    Caribbean
    First Language:
    English
    Primarily Uses:
    RMMV
    @Andar @Bex

    Okay, so I tried implementing your suggestion, Andar, and it basically works - just need to fine-tune stuff. However my set-up involves the event-to-be-guided calling a common event to alter the player image, etc, then enabling a parallel event that awaits for a touch trigger, moving the icon (player) to that location, then (how I have it set-up at the moment) having an enabled switch activate a page on the event-to-be-guided to move to that same location. Then clean-up stuff afterwards.

    The 1-frame wait loop method is way simpler, though lacks the fancy icon visualisation at the moment. I should be able to fine-tune both further, but can you inform me of downfalls to using the 1-frame wait method? From my perspective, I don't know what foreseeable errors can happen.

    Also, for the sake of learning, are there alternatives to this with javascripting? (Like the setInterval method I tried).
     
    #4

Share This Page