VX Jump Bug Fix

VX Jump Bug Fix
By: Gustavo Bicalho

Introduction

Well, a friend of mine just noticed that if you try to jump onto a impassable place on VX, it lets you do that. At the other RPG Makers the impossible jump waits untill it can be completed (may be never) or is ignored (if the ignore option is selected at the move event command), just like a normal move.
This little code makes VX jumps work like jumps from the older versions.

Script

  1. #==============================================================================
  2. # VX Jump Bug Fix
  3. #------------------------------------------------------------------------------
  4. # Author: Gustavo Bicalho
  5. #==============================================================================
  6.  
  7. class Game_Character
  8.   JUMP_IN_PLACE_IF_IMPOSSIBLE = false
  9.   alias :gus_jumpfix_jump :jump
  10.   def jump(x_plus, y_plus)
  11.     if !passable?(@x+x_plus, @y+y_plus)
  12.       return gus_jumpfix_jump(0,0) if (JUMP_IN_PLACE_IF_IMPOSSIBLE)
  13.       @move_failed = true
  14.       return
  15.     end
  16.     gus_jumpfix_jump(x_plus, y_plus)
  17.   end
  18. end
  19.  
Expand to see the code.


Instructions

Paste the code anywhere above Main and below Game_Character.
The constant JUMP_IN_PLACE_IF_IMPOSSIBLE allows a behavior modification: when you set it to true, if the jump is impossible the player will just jump in place. This is not the behavior you would expect at the older RM's, but I think it may be useful XD

Terms and Conditions

Use it as you wish, credits would be appreciated.
I personally think you shouldn't use a constant variable to do that.
Let's say someone has a jump system where he doesn't want to jump on impassable tiles, but wants to be able to do so in scripted events.
In this case, you're screwed because your variable is hard coded.

I think you should add this in Game_System as public variable (attr_accessor) so people can change this option on the fly.

Take care!
-Dargor
There's always a way to change a Constant value but only if it's an Array or Hash... that means JUMP_IN_PLACE_IF_IMPOSSIBLE = false should be transformed into an Array like this JUMP_IN_PLACE_IF_IMPOSSIBLE = [false]. Now every time you need to change it on the fly, you'll need to call like this way... JUMP_IN_PLACE_IF_IMPOSSIBLE[0] = false or true. It'd work best if included in a module not a class... but the module could be mixed in the class...
You are right. But changing constants is simply bad. Ruby constants are supposed to remain constant for the duration of the program. The Ruby interpreter does not actually enforce the constancy of constants, but it does issue a warning if a program changes the value of a constant. I'm not sure if it does this in RPG Maker but whatever, it's bad.

To be cleaner, you should add this at the top of your script

  1. class Game_System
  2.     attr_accessor :jump_in_place
  3.     alias :game_system_jump_initialize :initialize
  4.     def initialize
  5.       game_system_jump_initialize
  6.       @jump_in_place = false
  7.     end
  8.   end
  9. end
Expand to see the code.


Then replace this line:
return gus_jumpfix_jump(0,0) if (JUMP_IN_PLACE_IF_IMPOSSIBLE)

with this one:
return gus_jumpfix_jump(0,0) if $game_system.jump_in_place

You don't need to put this between parentheses.

Then, at any time in the game, you could call a script like this:
$game_system.jump_in_place = true/false

Also, by adding this variable to Game_System, it will be saved along with all other game data.
Quote:
You are right. But changing constants is simply bad. Ruby constants are supposed to remain constant for the duration of the program. The Ruby interpreter does not actually enforce the constancy of constants, but it does issue a warning if a program changes the value of a constant. I'm not sure if it does this in RPG Maker but whatever, it's bad.

Normally you'll be right, but the method I explained above doesn't even show a warning either in IRB or in RM.

I agree with you that it should be saved in the saved game data file, but you can even do that with constants and a ternary condition.

I just wanted to show you there are always several ways to achieve the same purpose (and normally RM ways aren't the best).
Actually, I thought about putting that setting in some global data variable like Dargor did. Or I could have a used a Switch.
But, remember, the main purpose of the script is to achieve the same behavior of the previous RPG Makers, and the "jump in place" thing is just an "extra". With that in mind, I left the option it in a constant for simplicity. Anyone who wants to change the behavior during the game can change the code to use a switch or something like that with little effort.

Anyway, thanks for the comments!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70039