Snippet that prevents F12 from restarting the game

Started by Zeriab, April 20, 2008, 05:27:05 pm

Previous topic - Next topic

Zeriab

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.

#=============================================================================
# ** 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:


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

shdwlink1993

Hey! This is pretty neat! Here's what happens on my game (in case you wanted to know what happens on different projects):

Battle was speed up through the roof! :D
Message text would not begin appearing until you hit the OK button, when it came all-at-once.
As long as the button was held down, no scene changes or teleports could occur (try tapping F12 with this while it tries changing maps. It looks really funny.)
In the map scene (sometimes) animations would appear, but they wouldn't actually animate. It would just show the first frame and stop. Curious.

But yea. Pretty neat! ;D Now all we need is a way to stop F1 and F2...
Stuff I've made:




"Never think you're perfect or else you'll stop improving yourself."

"Some people say the glass is half full... some half empty... I just wanna know who's been drinking my beer."

Zeriab

I'm glad you like it ^_^
The effects of pressing F12 can indeed be curious at times XD

Here is another version where the game should simply pause while F12 is pressed. (hopefully)
#=============================================================================
# ** 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


Why do you need a way to stop F2?
It like F9 only does something during test play. (When you play the game from the editor)

As for F1 you could simulate an additional F1 press when it is discovered. The dialog would probably blink up.
Why would you want to remove that dialog though? It's options the player can change, like if they have a slow computer they can deselect smooth mode

Fantasist

In the map, it only pauses the game, nice one Zeriab :)

Though, I'd like to see a complete disable. I wouldn't disable it if I were to make a game, I'd use your other fix. I prefer to give the player the option to do things like exit (Alt+F4) and Restart at his own will. I WOULD want to disable Alt+Enter.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

Hm, if it speeds up the game to really 410 fps... Maybe I will try it anyway. :3
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

MayorAnime

I just stumbled across this and tried out the later version, the one that pauses the game when you hold down F12.

Greatest - Screenshot - Setup - Ever.

Thanks, Zeriab!

Zeriab

I am glad you like it :3
Just ask if you ever have any problems with it.