XP and VX Output Console

Hi, today i show you my latest script.
It's a Console like RPG Maker VX Ace to show output.

You can use "console.log(object)" or "p object" to display information in the Console !


  1. #==============================================================================
  2. # ** Console Support for XP/VX
  3. #------------------------------------------------------------------------------
  4. # By Grim from http://www.biloucorp.com
  5. #==============================================================================
  6. # Function :
  7. #==============================================================================
  8. # Console.log(text)  => display text in console
  9. # console.log(text)  => display text in console
  10. #==============================================================================
  11. # ** Configuration
  12. #------------------------------------------------------------------------------
  13. # Configuration data
  14. #==============================================================================
  15.  
  16. module Configuration
  17.   #--------------------------------------------------------------------------
  18.   # * Active Console (true=>activate console, false=>unactivate console)
  19.   # * Only for XP and VX
  20.   #--------------------------------------------------------------------------
  21.   ENABLE_CONSOLE = true
  22. end
  23.  
  24. #==============================================================================
  25. # ** Util
  26. #------------------------------------------------------------------------------
  27. # Usefull tools
  28. #==============================================================================
  29.  
  30. module Util
  31.   #--------------------------------------------------------------------------
  32.   # * Singleton
  33.   #--------------------------------------------------------------------------
  34.   extend self
  35.   #--------------------------------------------------------------------------
  36.   # * if RPG MAKER XP
  37.   #--------------------------------------------------------------------------
  38.   def rpg_maker_xp?
  39.     defined?(Hangup)
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # * if RPG MAKER VX
  43.   #--------------------------------------------------------------------------
  44.   def rpg_maker_vx?
  45.     !rpg_maker_xp? && (RUBY_VERSION == '1.8.1')
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # * if RPG MAKER VXAce
  49.   #--------------------------------------------------------------------------
  50.   def rpg_maker_vxace?
  51.     RUBY_VERSION == '1.9.2'
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * alias
  55.   #--------------------------------------------------------------------------
  56.   alias :rmxp?    :rpg_maker_xp?
  57.   alias :rmvx?    :rpg_maker_vx?
  58.   alias :rmvxace? :rpg_maker_vxace?
  59.   #--------------------------------------------------------------------------
  60.   # * Get Screen Object
  61.   #--------------------------------------------------------------------------
  62.   def get_screen
  63.     return $game_map.screen if rpg_maker_vxace?
  64.     $game_screen
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Debug mode
  68.   #--------------------------------------------------------------------------
  69.   def from_editor?
  70.     $TEST || $DEBUG
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Get current Scene
  74.   #--------------------------------------------------------------------------
  75.   def scene
  76.     return SceneManager.scene if rpg_maker_vxace?
  77.     $scene
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Window Handle
  81.   #--------------------------------------------------------------------------
  82.   def handle
  83.     Win32API::FindWindowA.call('RGSS Player', 0)
  84.   end
  85. end
  86.  
  87. #==============================================================================
  88. # ** Win32API
  89. #------------------------------------------------------------------------------
  90. #  win32/registry is registry accessor library for Win32 platform.
  91. #  It uses dl/import to call Win32 Registry APIs.
  92. #==============================================================================
  93.  
  94. class Win32API
  95.   #--------------------------------------------------------------------------
  96.   # * Librairy
  97.   #--------------------------------------------------------------------------
  98.   AllocConsole        = self.new('kernel32', 'AllocConsole', 'v', 'l')
  99.   FindWindowA         = self.new('user32', 'FindWindowA', 'pp', 'i')
  100.   SetForegroundWindow = self.new('user32', 'SetForegroundWindow','l','l')
  101.   SetConsoleTitleA    = self.new('kernel32','SetConsoleTitleA','p','s')
  102.   WriteConsoleOutput  = self.new('kernel32', 'WriteConsoleOutput', 'lpllp', 'l' )
  103. end
  104.  
  105. #==============================================================================
  106. # ** Console
  107. #------------------------------------------------------------------------------
  108. #  VXAce Console Handling
  109. #==============================================================================
  110.  
  111. module Console
  112.   #--------------------------------------------------------------------------
  113.   # * Singleton
  114.   #--------------------------------------------------------------------------
  115.   extend self
  116.   #--------------------------------------------------------------------------
  117.   # * Initialize
  118.   #--------------------------------------------------------------------------
  119.   def init
  120.     unless Util.rmvxace?
  121.       return unless Util.from_editor?
  122.       Win32API::AllocConsole.call
  123.       Win32API::SetForegroundWindow.call(Util.handle)
  124.       Win32API::SetConsoleTitleA.call("RGSS Console")
  125.       $stdout.reopen('CONOUT$')
  126.     end
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Log
  130.   #--------------------------------------------------------------------------
  131.   def log(*data)
  132.     return unless Util.from_editor?
  133.     if Util.rmvxace?
  134.       p(*data)
  135.       return
  136.     end
  137.     return unless Configuration::ENABLE_CONSOLE
  138.     puts(*data.collect{|d|d.inspect})
  139.   end
  140. end
  141.  
  142. #==============================================================================
  143. # ** Kernel
  144. #------------------------------------------------------------------------------
  145. #  Object class methods are defined in this module.
  146. #  This ensures compatibility with top-level method redefinition.
  147. #==============================================================================
  148.  
  149. module Kernel
  150.   #--------------------------------------------------------------------------
  151.   # * Alias for console
  152.   #--------------------------------------------------------------------------
  153.   def console; Console; end
  154.   #--------------------------------------------------------------------------
  155.   # * pretty print
  156.   #--------------------------------------------------------------------------
  157.   if !Util.rmvxace? && Util.from_editor?
  158.     def p(*args)
  159.       console.log(*args)
  160.     end
  161.   end
  162. end
  163.  
  164. #--------------------------------------------------------------------------
  165. # * Initialize Console
  166. #--------------------------------------------------------------------------
  167. Console.init if Configuration::ENABLE_CONSOLE
Expand to see the code.


And original link here : https://github.com/Funkywork/Scripts-rm ... Console.rb
This is great, thanks. Much more useful than how I normally display stuff.
And if anyone needs an input script, this still exists :3
viewtopic.php?f=11&t=73929

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