Need help getting a custom warp tile working properly?

Hi, been toying around with using event names to have events - and one thing I've been using that to develop is a Game_Event script where the player touching an Event called WarpA - would warp the player to point WarpB, and vice-versa.

I'm having trouble though with getting the player to warp to B, and then instantly warp back to A.
The confusing part is the Warp from B to A works like it should, but the warp from A to B does not.

I don't know how smart it is to just dump code, but this it in it's entirety.
Spoiler
Code:
#==============================================================================
# * Warp Event Script
#-------------------------------------------------------------------------------
# Test: Name events to take on warp tile properties.
#==============================================================================
$player_lastwarp_x = 0
$player_lastwarp_y = 0
$player_can_warp = true
$WarpA_x = 0
$WarpA_y = 0
$WarpB_x = 0
$WarpB_y = 0
#-------------------------------------------------------------------------------
# * Game Event Class
#-------------------------------------------------------------------------------
class Game_Event < Game_Character
 
  #----------------------------------------------------------------------------
  # * Initialize
  #----------------------------------------------------------------------------
  alias init_warp_variables initialize
  def initialize(map_id, event)
  init_warp_variables(map_id, event)
   create_warp_coordinates
  end

  #---------------------------------------------------------------------------
  # * Create Warp Coordiantes
  #---------------------------------------------------------------------------
  def create_warp_coordinates
   
    if @event.name == "WarpA"
      $WarpA_x = @event.x
      $WarpA_y = @event.y
    end
   
    if @event.name == "WarpB"
      $WarpB_x = @event.x
      $WarpB_y = @event.y
    end
   
  end

  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias up_warp_tiles update
  def update
  up_warp_tiles
  super()
    warp_event
  end

  #-----------------------------------------------------------------------------
  # * Touch Event Call
  #-----------------------------------------------------------------------------
  def warp_event
   #----------------------------------------------------------------------------
   # * If the players coordinates are not equal to the coordinates entered from 
   #   warp, allow the player to warp again.
   #----------------------------------------------------------------------------
   if ($game_player.x != $player_lastwarp_x || $game_player.y != $player_lastwarp_y) && !$game_player.moving?
    $player_can_warp = true
    $player_lastwarp_x = -1
    $player_lastwarp_y = -1
   end
   #----------------------------------------------------------------------------
   # * If the players coordinates are equal to the coordinates entered from 
   #   warp, stop the player from warping again.
   #----------------------------------------------------------------------------   
   if ($game_player.x == $player_lastwarp_x && $game_player.y == $player_lastwarp_y) 
    $player_can_warp = false
   end
   
    #---------------------------------------------------------------------------
    # * Warp_Obj
    #---------------------------------------------------------------------------
    if @event.x == $game_player.x && @event.y == $game_player.y && $player_can_warp && $game_player.stopping?
     
    if @event.name == "WarpA"
     $player_lastwarp_x = $WarpB_x
     $player_lastwarp_y = $WarpB_y     
     $game_player.reserve_transfer(@map_id, $WarpB_x, $WarpB_y, $game_player.direction) 
    end
   
    if @event.name == "WarpB"
     $player_lastwarp_x = $WarpA_x
     $player_lastwarp_y = $WarpA_y
     $game_player.reserve_transfer(@map_id, $WarpA_x, $WarpA_y, $game_player.direction) 
    end   
   
   end
   
  end
 
end

So what's supposed to happen is when the player touches the tile, it warps the player and sets some variables related to that warp points position. If the players x and y matches those two variables warping won't work until he's not aligned with either one or both of the coordinate variables.

It works perfectly for the B warp, but just not the A warp and its driving me nuts.
Well you're using double "if", why not "elsif"?
There are many issues with that code, but the biggest one is this part:
Spoiler
Code:
  alias up_warp_tiles update
  def update
    up_warp_tiles
    super()
    warp_event
  end
You use the alias method and a super call in the same method.
You should either use the alias method or the super call, never both at the same time (unless they are conditioned in a way that only one of them can run at the same time).

And there is another thing I find a bit unnecessary here... The whole code...
I mean, if you are using events anyway, why wouldn't you do this in the events directly? You can transfer the player there too easily, you know which events you want to make as transport events, you know where you want to transport the player, and you can check positions in events too, so you have everything you need.
I just can't see the point in this script, at least not in this form.

You need to restructure that code if you want to go the "code-way", and re-check the logic you have in mind.
The first thing in that would be the answer to the "Do I really need to update the warp logic constantly?". I think, you know the answer for this already.
After that do what Theo already mentioned, use elsif or case statements instead of always using if. You don't have to check for the event's name twice there, since if it's one, it can't be the other one anyway, for example.
Also, you use global variables in a constantly updated method that runs for ALL events, regardless of their name. I suppose, it won't be a problem if you only have these 2 events you really want to check for on the map, but the moment you add a non-warp-related event, your logic goes poof in the abyss, because even that irrelevant event will update your global variables.

No idea if I missed something, but I'm out of coffee, so that's it for now. 😛
I guess the teleporters were a bad idea then. Was trying to see if I could get events to do other things outside of their event pages.
Thought it was a good idea - but I'm willing to give up on it.

Thanks for the tips on elsif's though.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-getting-a-custom-warp-tile-working-properly.102996/