How to get class name from Scripts.rxdata?
#1
I am trying to port Hime's Full Error Backtrace script to RPGmXP (this one)

It works fine as is (as long as you have that recently posts Console script) except that I get things like "Section086" instead of "Game_Player" so I can assume it is stored in a different place in scripts.rxdata.

here is the code if it helps (add it into the Main method)
Code:
rescue Exception => error #Exception => error
  scripts_name = load_data('Data/Scripts.rxdata')
  scripts_name.collect! {|script|  script[1]  }
  backtrace = []
  error.backtrace.each_with_index {|line,i|
    if line =~ /{(.*)}(.*)/
      backtrace << (scripts_name[$1.to_i] + $2)
    elsif line =~  /\A:1:/
      break
    else
      backtrace << line
    end
  }
  error_line = backtrace.first
  backtrace[0] = ''
  out_string = error_line + ": " + error.message + " (#{error.class})" + backtrace.join("\n\tfrom ") + "\n"
  console.log( out_string)
  raise  error.class, "Error ocurred, check the debug console for more information.", [error.backtrace.first]
Reply }
#2
Do you really need that backtracing script?

I have one in my project, i really don't know the scripter name (sorry dude), but the script helps me greatly: it shows the backtrace, the script names, the line and method called. And i'm writing a CMS \ CBS in my game.
Hope it helps.

To install it, just change this part of Main script...

Code:
rescue Errno::ENOENT
  
  # Aqui, definimos a mensagem padrão para Errno::ENOENT
  # Quando não é possível abrir um arquivo, a mensagem é exibida
  
  filename = $!.message.sub("Arquivo não encontrado - ", "")
  print("O Arquivo #{filename} não foi encontrado.")
end

For this.

Code:
rescue Errno::ENOENT
  
  # Aqui, definimos a mensagem padrão para Errno::ENOENT
  # Quando não é possível abrir um arquivo, a mensagem é exibida
  
  filename = $!.message.sub("Arquivo não encontrado - ", "")
  print("O Arquivo #{filename} não foi encontrado.")
  rescue StandardError => stderr
  # Bring message to user that an error has occured
  p "Your error message here. See Instructions for more details."
  # Optional, when debugging, you will still receive the error message, but in less details.
  if $DEBUG
    p stderr.message
  end
  # When?
  time = Time.now
  time = time.strftime("%a %d %b %Y, %X")
  # Write to file
  File.open("ErrorLog.rxdata","a+") do |fh|
    # Time
    fh.puts("Time: #{time}")
    # Error type
    fh.puts("Error type: #{stderr.class}")
    # In which class?
    fh.puts("Class: #{$scene.class}")
    # Message
    fh.puts("Message: #{stderr.message}")
    # Where?
    fh.puts("at")
    for location in stderr.backtrace
      # Get the section number
      section = location[/(?#Section)(\d)*(:)/]
      # Strip off anything but numbers
      section_err = section[0, section.length - 1]
      script_name = $RGSS_SCRIPTS[section_err.to_i][1]
      # Get line number
      line_num = location[/(:)(\d)*(\Z|(:))/]
      # Strip off anything but line number
      #line_num_err = line_num[section_err.length + 1, line_num.length - section_err.length]
      # Strip off ":" if any
      line_num_err = line_num[1, line_num.length - 1]
      line_num_err = line_num_err[/(\d)*/]
      # If any, get method name
      method = location[/\s\W(\w)*\W/]
      # Strip the space
      method = method[1, method.length - 1] unless method == nil
      # Now construct location string
      loc_err = script_name + ", line " + line_num_err +
        (method == nil ? "" : ", at " + method)
      # Write to file
      fh.puts("     #{loc_err}")
    end
    # Delimiter
    fh.puts("--------------------")
  end
end

The backtrace is saved in the file ErrorLog.rxdata in the project's root directory. Its a stream of characters, so any text editor can read it's data (Notepad, Wordpad, Notepad++, Sublime Text, etc).
Reply }
#3
That's what I was looking for: "script_name = $RGSS_SCRIPTS[section_err.to_i][1]"

Thanks!
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
  Icon Display 1.0 scripts makes events impossible to go to events, which are passable Djigit 0 3,880 01-03-2015, 09:11 PM
Last Post: Djigit
   looking for day/night/weather scripts: Ahzoh 2 5,003 07-31-2013, 05:25 AM
Last Post: Ahzoh
   RXDATA layout? Myownfriend 4 7,699 04-09-2013, 02:17 PM
Last Post: Myownfriend
   Modifying Actor ID to Class ID for Advanced Individual Battle Commands Script NewHope 1 4,617 07-11-2012, 11:37 PM
Last Post: NewHope
   MrMo's ABS Ultimate and Other Scripts Erechel 6 9,480 05-07-2012, 03:37 AM
Last Post: Erechel
   Replace the AUDIO class for RMXP! DerVVulfman 8 15,201 10-15-2010, 06:29 PM
Last Post: yamina-chan
   Combine two scripts Kerdukie 0 3,307 12-25-2009, 02:16 AM
Last Post: Kerdukie
   Calling Scripts aistinger 3 5,873 12-03-2009, 01:41 AM
Last Post: aistinger
   Sideview Tankentai XP & SDK Scripts Ravenith 1 5,354 08-26-2009, 03:01 AM
Last Post: DerVVulfman



Users browsing this thread: 1 Guest(s)