Save-Point
Stop F12 from resetting your game - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: Stop F12 from resetting your game (/thread-2477.html)



Stop F12 from resetting your game - Zeriab - 03-06-2008

Here is a rather useful snippet I just cooked up.
This prevents the F12 key from resetting the game.
For some reason pressing the F12 key now seems to speed up the game in many cases and in other pauses the game.

Code:
#=============================================================================
# ** Reset class (because it won't be defined until F12 is pressed otherwise)
#=============================================================================
class Reset < Exception
  
end
#=============================================================================
# ** Module Graphics
#=============================================================================
module Graphics
  class << self
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_f12_removal_update)
      alias_method(:zeriab_f12_removal_update, :update)
      alias_method(:zeriab_f12_removal_transition, :transition)
    end
    def update(*args)
      begin
        zeriab_f12_removal_update(*args)
      rescue Reset
        # Do nothing
      end
    end
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_removal_transition(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
  end
end
For an extreme example of the speed up issue I mentioned here is a picture:
[Image: speedboostlx8.png]

I don't know whether it actually went with 410 FPS or if something broke.

If the player press F12 during a transition the transition will reset and start again.
If F12 is kept pressed the game will feel like it has been paused. The FPS registered will typically be registered as higher although game playing will not change. Nor will it if it's Graphics.update being cancelled. The shown timer will however run faster.
Here is a snippet where it feels like the game simply pauses when pressing F12, if that is what one prefer:

Code:
#=============================================================================
# ** Reset class (because it won't be defined until F12 is pressed otherwise)
#=============================================================================
class Reset < Exception
  
end
#=============================================================================
# ** Module Graphics
#=============================================================================
module Graphics
  class << self
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_f12_removal_update)
      alias_method(:zeriab_f12_removal_update, :update)
      alias_method(:zeriab_f12_removal_transition, :transition)
    end
    def update(*args)
      done = false
      # Keep trying to do the update
      while !done
        begin
          zeriab_f12_removal_update(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_removal_transition(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
  end
end
*hugs*
- Zeriab