Save-Point
Console Output - 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: Console Output (/thread-4741.html)



Console Output - Grimimi - 07-22-2013

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 !


Code:
#==============================================================================
# ** Console Support for XP/VX
#------------------------------------------------------------------------------
# By Grim from http://www.biloucorp.com
#==============================================================================
# Function :
#==============================================================================
# Console.log(text)  => display text in console
# console.log(text)  => display text in console
#==============================================================================
# ** Configuration
#------------------------------------------------------------------------------
# Configuration data
#==============================================================================

module Configuration
  #--------------------------------------------------------------------------
  # * Active Console (true=>activate console, false=>unactivate console)
  # * Only for XP and VX
  #--------------------------------------------------------------------------
  ENABLE_CONSOLE = true
end

#==============================================================================
# ** Console
#------------------------------------------------------------------------------
#  VXAce Console Handling
#==============================================================================

module Console
  #--------------------------------------------------------------------------
  # * Librairy
  #--------------------------------------------------------------------------
  AllocConsole        = Win32API.new('kernel32', 'AllocConsole', 'v', 'l')
  FindWindowA         = Win32API.new('user32', 'FindWindowA', 'pp', 'i')
  SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow','l','l')
  SetConsoleTitleA    = Win32API.new('kernel32','SetConsoleTitleA','p','s')
  WriteConsoleOutput  = Win32API.new('kernel32', 'WriteConsoleOutput', 'lpllp', 'l' )
  #--------------------------------------------------------------------------
  # * Singleton
  #--------------------------------------------------------------------------
  extend self
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  def init
    if (RUBY_VERSION != '1.9.2')
      return unless ($TEST || $DEBUG)
      hwnd = FindWindowA.call('RGSS Player', 0)
      AllocConsole.call
      SetForegroundWindow.call(hwnd)
      SetConsoleTitleA.call("RGSS Console")
      $stdout.reopen('CONOUT$')
    end
  end
  #--------------------------------------------------------------------------
  # * Log
  #--------------------------------------------------------------------------
  def log(*data)
    return unless ($TEST || $DEBUG)
    if (RUBY_VERSION == '1.9.2')
      p(*data)
      return
    end
    return unless Configuration::ENABLE_CONSOLE
    puts(*data.collect{|d|d.inspect})
  end
end

#==============================================================================
# ** Kernel
#------------------------------------------------------------------------------
#  Object class methods are defined in this module.
#  This ensures compatibility with top-level method redefinition.
#==============================================================================

module Kernel
  #--------------------------------------------------------------------------
  # * Alias for console
  #--------------------------------------------------------------------------
  def console; Console; end
  #--------------------------------------------------------------------------
  # * pretty print
  #--------------------------------------------------------------------------
  if (RUBY_VERSION != '1.9.2') && ($TEST || $DEBUG)
    def p(*args)
      console.log(*args)
    end
  end
end

#--------------------------------------------------------------------------
# * Initialize Console
#-------------------------------------------------------------------------- Console.init if Configuration::ENABLE_CONSOLE



RE: Console Output - MechanicalPen - 07-22-2013

Hey cool I needed this!


RE: Console Output - MechanicalPen - 07-30-2013

Uhm? Even after removing the erroneous 'And original link here : https://github.com/Funkywork/Scripts-rm/blob/master/Toutes%20versions/XPVXConsole.rb' from the script, it still doesn't work. The console opens but none of the text is actually shown.

Edit: Oh I see, it is supposed to be 'CONOUT$'


RE: Console Output - MechanicalPen - 08-17-2013

It works now, thanks.