On-map "debugger" window

This little script adds a window to a map. This window is capable of displaying variables you'd like to check during test play, without leaving the map. I found it quite usefull while making my game so I decided to share it : ) Adding new variables is quite simple.

Screen (it's the thing in top-right corner):
http://img61.imageshack.us/img61/5691/debuggeruz1.jpg[/IMG]

Code:
class Bitmap
 
  def draw_var(x=0,y=0,w=640,h=32,var='')
    self.fill_rect(x,y,w,h,Color.new(255,255,255,32)) # back bar color
    self.draw_text(x,y,w,h,var,0)
    self.draw_text(x,y,w,h,eval(var).to_s,2)
  end
 
end
  #--------------------------------------------------------------------------
class Window_DOM < Window_Base
 
  def initialize
    super(352,0, 288, 256)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 16
    self.contents.font.bold = true
    self.contents.font.color = Color.new(200,200,255,160) #text color
    self.windowskin = nil
    refresh
  end
 
  def refresh
    if Input.repeat?(Input::F8)
      self.oy -= 8
    end
    if Input.repeat?(Input::F7)
      self.oy += 8
    end
    if Input.repeat?(Input::F6)
      self.oy = 0
    end
    self.contents.clear
    self.contents.draw_var(0, 0, 256, 16, '$game_map.display_x')
    self.contents.draw_var(0, 16, 256, 16, '$game_map.display_y')
    self.contents.draw_var(0, 32, 256, 16, '$game_player.x')
    self.contents.draw_var(0, 48, 256, 16, '$game_player.y')
  end
 
end
  #--------------------------------------------------------------------------
class Scene_Map
 
  alias dom_main main
  alias dom_update update
 
  def main
    @debugger = Window_DOM.new
    dom_main
    @debugger.dispose
  end
 
  def update
    @debugger.refresh
    dom_update
  end
 
end
Expand to see the code.


Gukosowa's version:
#==============================================================================
# ** In Map Debugger - Programming Tool
#------------------------------------------------------------------------------
#  Original   ? arevulopapo
#  Masteredit ? markusmks
#-------------------------
# ** Features
#    Add Global Variable with $debugger.add(var name) eg: $game_map.display_x
#    Add Feature 2: You can set a alias name of var name.
#      eg: $debugger.add(variable,alias name). So the result of variable is set to
#          screen, and the text of alias name.
#    Add Feature 3: You can add Custom Debug Variables with alias text
#          in Line 53.
#      Especially for Call Script, because the small window size.
#      You can add also Variables in alias text, it refreshes every 50 Frames.
#      eg. text = $game_party.actors[0].weapon_id.to_s
#          alias_text = text+" Weapon Equiped"
#
#    Delete Var with $debugger.delete(value) eg: 1 (Variable ID) in Debugger
#    Delete Method 2: $debugger.delete_value(value)
#                                       eg: $game_map.display_x is included
#
#    If you add a Global Variable which is already added, nothing happens
#
#    You can switch the visible of the Debugger (ON::OFF) if you press F5.
#      if it switched it OFF performance is bigger.
#==============================================================================

class Debugger
  attr_accessor :amount_values
  #--------------------------------------------------------------------------
  # * initialize
  #--------------------------------------------------------------------------
  def initialize
    # OPTIONS #########################################
    #                             RED,GRE,BLU,opacity
    @colour_text      = Color.new(200,200,255,255)
    @text_back_colour = Color.new(000,000,000,100)
    @text_size        = 16
    @y                = 0
    @width            = 300 #288
    @height           = 256
    @x                = 640-@width
    ###################################################
    @show_custom   = []
    @amount_values = []
    add '$game_map.display_x'
    add '$game_map.display_y'
  end
  #--------------------------------------------------------------------------
  # * add custom variable '' especially for Call Script in Game
  #--------------------------------------------------------------------------
  def custom_var(id,delete=false,return_var=false)
    alias_text = nil
    case id
    when 0
      var = '$game_map.display_x'
      alias_text = 'Player Display X'
    when 1
      var = '$game_map.display_y'
      alias_text = 'Player Display Y'
    when 2
      var = '$game_player.x'
    when 3
      var = '$game_player.y'
    end
    if return_var
      return var,alias_text
    end
    if !delete
      @show_custom.push id
      @show_custom = @show_custom.uniq
      add(var,alias_text)
    else
      @show_custom.delete id
      delete_value(var)
    end
  end
  #--------------------------------------------------------------------------
  # * refresh custom text '' especially for Call Script and alias_text
  #--------------------------------------------------------------------------
  def refresh_custom(id)
    return if !@show_custom.include? id
    custom_var(id,true)
    custom_var(id,false,false)
  end
  #--------------------------------------------------------------------------
  # * add
  #--------------------------------------------------------------------------
  def add(variable,alias_name=nil)
    if alias_name == nil
      @amount_values.push variable
    else
      @amount_values.push [variable,alias_name]
    end
    @amount_values = @amount_values.uniq
  end
  #--------------------------------------------------------------------------
  # * delete variable
  #--------------------------------------------------------------------------
  def delete(value)
    return if value == nil
    @amount_values.delete_at(value)
  end
  #--------------------------------------------------------------------------
  # * delete value
  #--------------------------------------------------------------------------
  def delete_value(variable)
    id = get_value(variable)
    id = @amount_values.rindex(variable) if id == nil
    delete id
  end
  #--------------------------------------------------------------------------
  # * return id from variable
  #--------------------------------------------------------------------------
  def get_value(variable)
    i = -1
    id = nil
    variable = variable[0] if variable.is_a? Array
    for value in @amount_values
      i += 1
      next if !value.is_a? Array
      if variable == value[0]
        id = i
        break
      end
    end
    id = @amount_values.rindex(variable.to_s) if id == nil
    return id
  end
  #--------------------------------------------------------------------------
  # * get_value
  #--------------------------------------------------------------------------
  def get_data(value)
    return eval("@"+value.to_s)
  end
end
$debugger = Debugger.new

#==============================================================================
# ** Window_Debugger
#------------------------------------------------------------------------------
# 
#==============================================================================

class Window_Debugger < Window_Base
  #--------------------------------------------------------------------------
  # * initialize
  #--------------------------------------------------------------------------
  def initialize
    x = $debugger.get_data "x"
    y = $debugger.get_data "y"
    width  = $debugger.get_data "width"
    height = $debugger.get_data "height"
    colour_text = $debugger.get_data "colour_text"
    @text_back_colour = $debugger.get_data "text_back_colour"
    @text_size = $debugger.get_data "text_size"
    super(x,y,width,height)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = @text_size
    self.contents.font.bold = true
    self.contents.font.color = colour_text
    self.windowskin = nil
    self.visible = $DEBUG ? true : false
    @refresh_timer_max = 50
    @refresh_timer = @refresh_timer_max
    refresh
  end
  #--------------------------------------------------------------------------
  # * debugg_refresh
  #--------------------------------------------------------------------------
  def debugg_refresh
    for i in 0..999
      if $debugger.custom_var(i,false,true)[0] == nil
        break
      end
      id = i
    end
    for i in 0..id
      $debugger.refresh_custom(i)
    end
  end
  #--------------------------------------------------------------------------
  # * refresh
  #--------------------------------------------------------------------------
  def refresh
    if $DEBUG && Input.repeat?(Input::F5)
      self.visible = self.visible == true ? false : true
    end
    return if !self.visible
    if self.visible
      @refresh_timer = @refresh_timer <= 0 ? @refresh_timer_max : @refresh_timer-1
      debugg_refresh if @refresh_timer <= 0
      self.contents.clear
      for i in 0...$debugger.amount_values.size
        variable = $debugger.amount_values[i]
        variable2 = nil
        if variable.is_a? Array
          variable2 = variable[1]
          variable = variable[0]
        end
        self.contents.draw_var(i,i*@text_size, 256, @text_size, variable.to_s,
          @text_back_colour,variable2)
      end
    end
  end
end
#==============================================================================
# ** Bitmap **update
#------------------------------------------------------------------------------
#  A Bitmap class update to show a variable with value
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # * draw_variable
  #--------------------------------------------------------------------------
  def draw_var(i,y=0,w=640,h=32,var='',color=Color.new(255,255,255,32),add=nil)
    self.fill_rect(12,y,w,h,color)
    self.draw_text(14,y,w,h,i.to_s)
    self.draw_text(28,y,w,h,":")
    text = add == nil ? var : add
    self.draw_text(32,y,w,h,text.to_s)
    self.draw_text(10,y,w,h,eval(var).to_s,2)
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  - alias to Scene_Map
#    method to - main
#              - update
#==============================================================================

class Scene_Map
  attr_accessor :debugger
  #--------------------------------------------------------------------------
  # * main
  #--------------------------------------------------------------------------
  alias debugger_scene_map_main main
  def main
    @debugger = Window_Debugger.new
    debugger_scene_map_main
    @debugger.dispose
  end
  #--------------------------------------------------------------------------
  # * update
  #--------------------------------------------------------------------------
  alias debugger_scene_map_update update
  def update
    @debugger.refresh
    debugger_scene_map_update
  end
end
Expand to see the code.


Instructions:
Paste the code above main. New variables are added like this:
self.contents.draw_var(0, 0, 256, 16, '$game_map.display_x')
Expand to see the code.

You just add the variable's name as a string and the script prints it's name, and then evaluates it to print it's value, thus saving half the time it would take to do this. The (0,0,256,16) rectangle fits current window size and font size of 16, but it can be changed. The second value represents the y of the text, so it has to be adjusted for each nee line. Also, the colors may require to be changed, as I tested it mostly on dark maps and they may turn out bad on brighter ones. If the contents exceedes the window size you can scroll it with F8 and F7. F6 returns to default position, in case you'd get lost :p

Enjoy.
very easy to use.. and helpful in my 2nd Project too.. thx ^^
Wow... I really like the idea of an on-map debug info window, but how in the name of god did you do that 3D system? Did you just mess with the direction definitions to make them oblique and use parametric tiles, or is it an elaborate system? Wait... does the character even move obliquely at all? I mean parallel to the walls and not just the 8-dir fix? I'd really like to know. And you seem to be using the Particle system...
I'm using f0tz's 'New Pixelmovement Script' which allows that kind of advanced movement. And the particle system is mine, still in development, but I'll release it once it's fully done. Glad you like it so much : )
BUMP! Gukosowa (markusmks) has created a new version of this debugger. The code (and instructions in it) is in the first post.
The picture you have there makes your game sort of baldurus gate dark alliance sort of gameplay.It's really cool, i would surely play it
Great work. It is very useful so far!

I made TEXT black and the RECT white, and it looks ugly, but at least I can see it perfectly!

Peace!
This is very helpful, thank you.

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