#==============================================================================
# Get Error Info [VXA]
# Author: Mesiah A.K.A. Mako Infused
# Version: 1.00
# Contact: www.cetrastudios.com/
#------------------------------------------------------------------------------
# ■ Short Description
#------------------------------------------------------------------------------
# This script allows my scripts, as well as any other scripts which decide
# to support this, from giving a detailed description of how an event went
# wrong. Whenever a scripter deems a script call to be incorrect, a messagebox 
# is displayed explaining to the developer how it is inappropriate. In addition, 
# the exact location of the script call place of error is given as well as the 
# offending piece of code. This will make debugging much easier, hopefully 
# eliminating the need for some basic support that is usually required with 
# publishing scripts as well as streamlining the process.
# 
# As I make updates to this script, I will try to automatic the process a bit 
# more, giving the option to display more detailed information when the game 
# interpreter gives a generic "eval" error.
#
#------------------------------------------------------------------------------
# ͏ Notetags - 0
#------------------------------------------------------------------------------
# There is no notetag options for this script.
#
#------------------------------------------------------------------------------
# ͏ Script Calls - 0
#------------------------------------------------------------------------------
# There is no script calls for this script.
# 
#------------------------------------------------------------------------------
# ● Examples:
#------------------------------------------------------------------------------
# There are not examples needed for this script.
# 
#------------------------------------------------------------------------------
# ● Customization:
#------------------------------------------------------------------------------
# There is no customization options for this script.
#------------------------------------------------------------------------------
# ● Requirements:
#------------------------------------------------------------------------------
# This script must be placed above all other CUSTOM scripts.
#------------------------------------------------------------------------------
# * Terms:
#------------------------------------------------------------------------------
# - Don't claim you made this script.
# - Credit is appreciated, but not necessary.
#------------------------------------------------------------------------------
# ● Change Log:
#------------------------------------------------------------------------------
# 04/11/2013 - Started and finished script.
#==============================================================================

#==============================================================================
# [STOP] End of Edittable Area
#==============================================================================

$imported = {} if $imported.nil?
$imported["MESI-GetErrorInfo"] = true

#==============================================================================
# ** Game_CommonEvent
#==============================================================================

class Game_CommonEvent
  
  #--------------------------------------------------------------------------
  # * Alias Method: Initialize
  #--------------------------------------------------------------------------
  alias mesiah_gei_initialize initialize
  def initialize(common_event_id)
    mesiah_gei_initialize(common_event_id)
    @event_id = common_event_id
  end
  
  #--------------------------------------------------------------------------
  # * Overwrite Method: Update
  #--------------------------------------------------------------------------
  def update
    if @interpreter
      @interpreter.setup(@event.list, 0, @event_id) unless @interpreter.running?
      @interpreter.update
    end
  end
end

#==============================================================================
# ** Game_Interpreter
#==============================================================================

class Game_Interpreter
  
  #--------------------------------------------------------------------------
  # * Alias Method: Clear
  #--------------------------------------------------------------------------
  alias mesiah_gei_clear clear
  def clear
    mesiah_gei_clear
    @common_id = 0
  end
  
  #--------------------------------------------------------------------------
  # * Alias Method: Setup
  #--------------------------------------------------------------------------
  alias mesiah_gei_setup setup
  def setup(list, event_id = 0, common_id = 0)
    mesiah_gei_setup(list, event_id)
    @common_id = common_id
  end
  
  #--------------------------------------------------------------------------
  # * Overwrite Method: Setup Reserved Common Events 
  #--------------------------------------------------------------------------
  def setup_reserved_common_event
    if $game_temp.common_event_reserved?
      setup($game_temp.reserved_common_event.list, 0, $game_temp.common_event_id)
      $game_temp.clear_common_event
      true
    else
      false
    end
  end
  
  #--------------------------------------------------------------------------
  # * Is this event a common event, or a regular one?
  #--------------------------------------------------------------------------
  def common_event?
    @common_id > 0 ? true : false
  end
  
  #--------------------------------------------------------------------------
  # * Displays an error with detailed location information
  #--------------------------------------------------------------------------
  def event_script_error(line_id, message)
    line = caller[line_id][/:(\d+):/, 1]
    name = @list[@index].parameters
    if common_event?
      title = "Common ID"
      id = @common_id
    else
      title = "Event ID"
      id = @event_id
    end
    info1 = "#{title}: #{id} (Line: #{@index + line.to_i})"
    info2 = "Code: '#{name[0]}'"
    info3 = "-----------------------------------"
    msgbox(info1 + "\n" + info2 + "\n" + info3 + "\n" + message)
  end
  
end