Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Closed TopicStart new topic
> Advanced RGSS3 Console
berka
post Jan 21 2012, 04:16 PM
Post #1


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




Advanced RGSS3 Console
Version: 0.3
By: Berka

Introduction

I think the addition of the console has been the greatest feature of RMVX Ace: super handy for debugging scripts.
And that's why I could not resist the urge to customize this wonderful tool.

Features

  • Syntax highlighting,
  • Gets method,
  • Line numbers,
  • Simple color changer


Screenshots



Script

CODE
#============================================================
#                     Advanced RGSS3 Console
#   Berka          http://www.rpgmakervx-fr.com
#                   v0.5 VX Ace only. 01-21-12  
#
# Thanks to Azuma-01 for symbols and regexp matching
# Free of use. Please ask me before publishing anywhere.
#
# Add a basic syntax haighlighter to the default RGSS Console
# May cause a slight slowdown in the console display.
#------------------------------------------------------------
# Use Kernel#puts to activate the syntax highlighter.
# Kernel#print stays unchanged.$
# Console#gets extracts the input of the console
#   use: eval(Console.gets) to script while testing.
#------------------------------------------------------------
# Change the color of the console:
#   Console.color(H_RED)       # Set the color of the console
#   print("this text is red")  # Text displayed in red
#   Console.color = nil        # Remove the coloration
#============================================================

module Berka
  module Console
    LINE_NUMBERS = true  # Display line numbers ON/OFF
    BACKGROUND   = true  # Display a white background ON/OFF
    ENABLEPROMPT = true  # Enable the gets command ON/OFF
    PARSE_P      = false # Enable parsing for Kernel#p function /!\
  end
end

module Win32
  GSH ||= Win32API.new('kernel32','GetStdHandle','l','l')
  SCTA||= Win32API.new('kernel32','SetConsoleTextAttribute','ll','l')
end

module Highlighter  
  H_BLACK     = 0x0000 # black
  H_DBLUE     = 0x0001 # dark blue
  H_DGREEN    = 0x0002 # dark green
  H_DCYAN     = 0x0003 # dark cyan
  H_DRED      = 0x0004 # dark red
  H_DPURPLE   = 0x0005 # dark purple
  H_DYELLOW   = 0x0006 # dark yellow
  H_GREY      = 0x0007 # grey
  H_DGREY     = 0x0008 # dark grey
  H_BLUE      = 0x0009 # blue
  H_GREEN     = 0x000a # green
  H_CYAN      = 0x000b # cyan
  H_RED       = 0x000c # red
  H_PURPLE    = 0x000d # purple
  H_YELLOW    = 0x000e # yellow
  H_WHITE     = 0x000f # white
  H_INTENSITY = 0x0080 # background intensity
  
  # Ruby's special words
  H_KWORDS=["alias","begin","BEGIN","break","case","defined","do","else","elsif",
            "end","END","ensure","for","if","in","include","loop","next","raise",
            "redo","rescue","retry","return","super","then","undef","unless",
            "until","when","while","yield","false","nil","self","true","__FILE__",
            "__LINE__","and","not","or","def","class","module","catch","fail",
            "load","throw"]
            
  # Ruby's operators
  H_OPERATORS=["=","+","-","/","*","%",'(',')','[',']','{','}','<','>','&','|',
               ',','!',"?",":",";",'.']
  
  def self.parse(*args)
    args.flatten.each{|l|
      Console.color=nil
      print("#{sprintf("%03d",$consolelines+=1)}:\s")if Berka::Console::LINE_NUMBERS
      l.split(/ /).each{|e|
        case e
        when *H_KWORDS then Console.color=H_BLUE
        when /^\d*[.]?\d+$/ then Console.color=H_DRED
        when /\/.*\/(?:[imx]{,3})/ then Console.color=H_DPURPLE # by Azuma-01
        when /^:.*$/ then Console.color=H_DYELLOW # by Azuma-01
        when /^#.*$/ then Console.color=H_DGREEN # by Azuma-01
        else
          e.split(//).each{|f|
            @s=!@s if r=(f=='"'||f=="'")
            if(@s)||r;Console.color=H_DPURPLE
            elsif f=~/^\d*[.]?\d+$/;Console.color=H_DRED
            else
              Console.color=(H_OPERATORS.include?(f)? H_DCYAN : H_BLACK)
            end
            print(f)
          }
          print(" ")
          next
        end
        print("#{e} ")
      }
    }
    print("\n")
  end
end

include Highlighter

module Console
  $consolelines=0 # Console lines counter
  def self.init
    @outhwnd=Win32::GSH.call(-11)
  end
  def self.color=(c=H_BLACK)
    Win32::SCTA.call(@outhwnd,(c||=H_BLACK)|(Berka::Console::BACKGROUND ? 0x00f0 : 0))# rescue nil
  end
  def self.gets
    $stdin.gets
  end
end
Console.init

# Kernel#puts redefinition
def puts(*a)
  a.each{|n|Highlighter.parse(*n)}
end
#Kernel#p redefinition
def p(*a)
  Berka::Console::PARSE_P ? (a.each{|b|puts b.inspect}) : Kernel.p(*a)
end
# Kernel#gets
def gets
  Console.gets
end


Instructions

Paste this script above Vocab. Only the method Kernel#puts is modified. It enables the syntax highlighter:
CODE
puts("a = ['this is a test', 1.0]")

Kernel#print is not modified and it allows to color each line separately.
CODE
Console.color = H_RED
  print("Ruby is amazing")

The list of colors is mentionned at the beginning of the script.

Compatibility

No issues known yet.

Credits and Thanks

All thanks go to the Msdn reference.

Terms and Conditions

This script is free to use. Credits are not mandatory, but it would be very nice of you to quote me. Please ASK me before posting this script anywhere. Because of that I can help you to use this script.

Best regards,

Berka

This post has been edited by berka: Jan 24 2012, 03:43 PM


__________________________
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Jan 21 2012, 11:36 PM
Post #2


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




This is one the best things I've ever seen.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
berka
post Jan 24 2012, 03:02 PM
Post #3


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




New version:

- Regexp coloration
- Symbols coloration
Thanks to Azuma-01 for the regexp

Regards,

Berka


__________________________
Go to the top of the page
 
+Quote Post
   
h0Ax8omb3r
post Apr 8 2012, 03:59 AM
Post #4


Level 1
Group Icon

Group: Member
Posts: 5
Type: Developer
RM Skill: Beginner




think compatability may be a little off in vx i got this error
Script'Advanced RGGS3' line 33: NameError occured.
uninitialised constant Win32::GSH
Attached File  error.png ( 58.65K ) Number of downloads: 5


__________________________
It is I Ansem, Bringer of Darkness!
Go to the top of the page
 
+Quote Post
   
Pacman
post Apr 8 2012, 06:24 AM
Post #5


Level 3
Group Icon

Group: Member
Posts: 34
Type: Scripter
RM Skill: Advanced




This is a VXA script. It's not intended for VX.


__________________________
Go to the top of the page
 
+Quote Post
   
h0Ax8omb3r
post Apr 9 2012, 01:37 AM
Post #6


Level 1
Group Icon

Group: Member
Posts: 5
Type: Developer
RM Skill: Beginner




QUOTE (Pacman @ Apr 8 2012, 03:24 PM) *
This is a VXA script. It's not intended for VX.

ah ok thanks


__________________________
It is I Ansem, Bringer of Darkness!
Go to the top of the page
 
+Quote Post
   

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 08:33 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker