Need help getting a custom warp tile working properly?

sleepy_sealion

Need to work harder!
Veteran
Joined
Jan 4, 2018
Messages
245
Reaction score
429
First Language
English
Primarily Uses
RMVXA
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.
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
Well you're using double "if", why not "elsif"?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
There are many issues with that code, but the biggest one is this part:
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. :p
 

sleepy_sealion

Need to work harder!
Veteran
Joined
Jan 4, 2018
Messages
245
Reaction score
429
First Language
English
Primarily Uses
RMVXA
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top