Waiting for movement

Post date: Jan 07, 2010 1:39:46 PM

To show one use of Interpreter command_355 (RMXP) I'll show how you can make events wait for movement of a single event or the player to finish rather than all movements which the Wait For Movement's Completion command does.

Let's add this little snippet for checking whether Game_Character is moving or not. (Both Game_Player and Game_Event inherits from that class: (Add anywhere above main)

    1. class Game_Character

    2. ##

    3. # Returns :wait while the character is moving and

    4. # returns nil otherwise

    5. #

    6. def wait_for_movement

    7. if @move_route_forcing

    8. return :wait

    9. end

    10. end

  1. end

It returns :wait when called. You can now put $game_player.wait_for_movement in a script call and that event will wait until the player has stopped moving before continuing.

Likewise you can use $game_map.events[7].wait_for_movement for waiting until the event with id 7 has finished its movement.

It's simple, elegant and much easier than had the wait functionality been removed from command_355. It was an excellent idea in the default scripts albeit a little poorly executed and unfortunately not well-understood.

Next I will add some syntactic sugar to use in the call scripts which makes waiting for specific events easier. It's not needed at all, but it is more user friendly and nicer to use.

Add this script anywhere above main:

    1. class Interpreter

    2. ##

    3. # Wait for movement where: (Nothing will happen in combat)

    4. # id < 0: Current event (if there is one)

    5. # id = 0: Player

    6. # id > 0: Event with that id (if there is one)

    7. #

    8. def wait_for_movement(id = -1)

    9. # If in battle

    10. return if $game_temp.in_battle

    11. # Get actor

    12. actor = nil

    13. if id < 0 && @event_id > 0

    14. actor = $game_map.events[@event_id]

    15. elsif id == 0

    16. actor = $game_player

    17. else

    18. actor = $game_map.events[id]

    19. end

    20. # Wait for actor's movement

    21. unless actor.nil?

    22. actor.wait_for_movement

    23. end

    24. end

    25. ##

    26. # Wait for player's movement

    27. #

    28. def wait_for_players_movement

    29. wait_for_movement(0)

    30. end

  1. end

You can now simply put wait_for_movement in a script call and it will wait for its own movement to to be completed. (Note that it will simply skip if the interpreter does not originate from a map event. See my Common Events tutorial for more information on this subject)

You can specify a specific with wait_for_movement(id) where id is the id of the map event. If you for example want to wait for event 7 then use wait_for_movement(7).

You can wait for the player by using wait_for_movement(0) or by using wait_for_players_movement.

Note that it will do nothing if called in battle.