Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: ForeverZer0 on November 25, 2010, 04:55:17 pm

Title: [XP][VX] Console Output Debugger
Post by: ForeverZer0 on November 25, 2010, 04:55:17 pm
Console Output
Authors: ForeverZer0
Version: 1.0
Type: Scripting Tool
Key Term: Scripting Tool



Introduction

Redirects output using the "puts" command to a seperate console, instead of using the normal pop-up windows.
Noy much more to it than that.


Features




Screenshots

None.


Demo

None.


Script

Here.
Spoiler: ShowHide

if $DEBUG || $TEST
 # Create a console object and redirect standard output to it.
 Win32API.new('kernel32', 'AllocConsole', 'V', 'L').call
 $stdout.reopen('CONOUT$')
 # Find the game title.
 ini = Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
 title = "\0" * 256
 ini.call('Game', 'Title', '', title, 256, '.\\Game.ini')
 title.delete!("\0")
 # Set the game window as the top-most window.
 hwnd = Win32API.new('user32', 'FindWindowA', 'PP', 'L').call('RGSS Player', title)  
 Win32API.new('user32', 'SetForegroundWindow', 'L', 'L').call(hwnd)
 # Set the title of the console debug window'
 Win32API.new('kernel32','SetConsoleTitleA','P','S').call("#{title} :  Debug Console")
 # Draw the header, displaying current time.
 puts ('=' * 75, Time.now, '=' * 75, "\n")
end


To give the ouput the same functionality of the "p" method where it shows the inspected object, just add this code any 'ol where:

Spoiler: ShowHide
alias zer0_console_inspect puts
def puts(*args)
 inspected = args.collect {|arg| arg.inspect }
 zer0_console_inspect(*inspected)
end




Instructions

Place the script anywhere you like.
In script calls or within scripts, output to it using "puts" instead of the normal "p" or "print".


Compatibility

Shouldn't be any.


Credits and Thanks




Author's Notes

Please report any bugs/issues/suggestions. I will be happy to fix them.
Enjoy!
Title: Re: [XP][VX] Console Output Debugger
Post by: Blizzard on November 25, 2010, 05:51:45 pm
Hah! He did it! Great job, F0!
Title: Re: [XP][VX] Console Output Debugger
Post by: Ryex on November 26, 2010, 01:00:27 am
dose this work with the p and print commands too? or just puts?
in any case I've been wanting this for a while now. the pop up boxes make it hard to do debugging sometimes other times they are useful as they pause execution long enough to see data but keep the game running at full speed. this would of been real useful when I was making the DEE and dynamic sounds scripts.
Title: Re: [XP][VX] Console Output Debugger
Post by: ForeverZer0 on November 26, 2010, 08:44:13 am
Only with "puts". I left p and print alone, since it is sometimes useful to have exucution stop so you find exactly where something is going wrong.