设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 7404|回复: 17
打印 上一主题 下一主题

[RMVX发布] 【vx】错误脚本详细提示和添加错误日志

 关闭 [复制链接]

Lv3.寻梦者

梦石
0
星屑
1624
在线时间
1609 小时
注册时间
2007-8-28
帖子
3253

第3届短篇游戏大赛主流游戏组冠军第1届Title华丽大赛新人奖

跳转到指定楼层
1
发表于 2008-2-24 05:37:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 小幽的马甲 于 2010-10-5 19:45 编辑
  1. module ERRSettings
  2.   #▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  3.   #请设置以下东东
  4.   # 游戏测试的时候,是否保存错误信息?(true是false不是)
  5.   SaveErrorData = true
  6.   
  7.   # 回溯跟踪错误的文件名
  8.   BackTraceFileName = "Backtrace.txt"
  9.   #▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  10. end

  11. module RPG
  12.   module_function
  13.   def version
  14.     case
  15.       when defined? Hangup then 1.0
  16.       else 2.0
  17.     end
  18.   end
  19.   def debug?
  20.     $TEST or $DEBUG
  21.   end
  22. end
  23. class Reset < Exception
  24. end
  25. class ScriptInterpreter
  26.   
  27.   include ERRSettings
  28.   CallSystemError = true
  29.   def run
  30.     Graphics.freeze
  31.     $scene = Scene_Title.new
  32.     $scene.main until $scene.nil?
  33.     Graphics.transition(RPG.version == 1 ? 20 : 30)
  34.     exit
  35.   rescue Reset => exp
  36.     raise
  37.   rescue SystemExit => exp
  38.     raise
  39.   rescue Exception => exp
  40.     exception(exp)
  41.     exit
  42.   end
  43.   
  44.   private

  45.   def exception(exp)
  46.     save_backtrace(exp) if SaveErrorData or RPG.debug?
  47.     print(get_error_message(exp))
  48.     raise if CallSystemError and RPG.debug?
  49.   end

  50.   def get_error_message(exp)
  51.     if RPG.debug?
  52.       bt = BackTrace.get_backtraces(exp.backtrace)
  53.       
  54.       if exp.class.to_s=="SyntaxError"
  55.         $outexp="语法错误"
  56.       elsif exp.class.to_s=="NameError"
  57.         $outexp="变量未定义"
  58.       elsif exp.class.to_s=="NoMethodError"
  59.         $outexp="方法未定义"
  60.       elsif exp.class.to_s=="NoMemoryError"
  61.         $outexp="内存占有过大"
  62.       elsif exp.class.to_s=="ArgumentError"
  63.         $outexp="参数错误"   #如果愿意此处可以自定义添加
  64.       else
  65.         $outexp=exp.class.to_s
  66.       end

  67.       msg  = "◆ 发生错误\n"
  68.       msg += "\n66RPG提醒您:请养成备份游戏文件的习惯。\n \n"
  69.       msg += "错误类型 :\n\t#{$outexp}\n"
  70.       msg += "错误信息 :\n\t#{exp.message}\n" if exp.message
  71.       msg += "错误可能发生的相关位置 :"
  72.       bt.each do |i|
  73.         msg += " \n\t#{i.name} : 第 #{i.line_no} 行"
  74.         msg += " : #{i.method_name}" if i.method_name
  75.       end
  76.       msg += "  \n非常荣幸能为您发送错误报告\n"
  77.     else
  78.       msg  = "内部发生错误强制结束。\n"
  79.       msg += "66RPG提醒您:请养成备份游戏文件的习惯。\n"
  80.       msg += "▲错误报告文件「#{BackTraceFileName}」已经保存。\n\n"
  81.       msg += "  非常荣幸能为您发送错误报告\n"
  82.     end
  83.     msg
  84.   end
  85.   
  86.   def save_backtrace(exp)
  87.     bt = BackTrace.get_backtraces(exp.backtrace)
  88.    
  89.       if exp.class.to_s=="SyntaxError"
  90.         $outexp="语法错误"
  91.       elsif exp.class.to_s=="NameError"
  92.         $outexp="变量未定义"
  93.       elsif exp.class.to_s=="NoMethodError"
  94.         $outexp="方法未定义"
  95.       elsif exp.class.to_s=="NoMemoryError"
  96.         $outexp="内存占有过大"
  97.       elsif exp.class.to_s=="ArgumentError"
  98.         $outexp="参数错误"   #如果愿意此处可以自定义添加
  99.       else
  100.         $outexp=exp.class.to_s
  101.       end
  102.    
  103.     msg  = "◆ #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}\n"
  104.     msg += "错误类型 :\n\t#{$outexp}\n"
  105.     msg += "错误信息 :\n\t#{exp.message}\n" if exp.message
  106.     msg += "错误可能发生的相关位置 :"
  107.     bt.each do |i|
  108.       msg += " \n\t#{i.name} : 第 #{i.line_no} 行"
  109.       msg += " : #{i.method_name}" if i.method_name
  110.     end
  111.     msg += "\n-------------66RPG-------------------\n"
  112.     File.open(BackTraceFileName, "a") do |file|
  113.       file.write(msg)
  114.     end
  115.   end
  116. end

  117. # 回溯跟踪错误的类
  118. class BackTrace  
  119.   BacktraceRegexp = /^Section([0-9]+):([0-9]+)(:in `(.+)')?$/
  120.   def self.get_backtraces(bt)
  121.     r = []
  122.     bt.each do |i|
  123.       r << self.new(i)
  124.     end
  125.     r
  126.   end  
  127.   def initialize(line)
  128.     name, @line_no, @method_name =
  129.                                     BacktraceRegexp.match(line).to_a.values_at(1,2,4)
  130.     @name = get_section_name(name)
  131.   end  
  132.   attr_accessor :name
  133.   attr_accessor :line_no
  134.   attr_accessor :method_name  
  135.   private
  136.   def get_section_name(index)
  137.     $RGSS_SCRIPTS[index.to_i][1]
  138.   end
  139. end
  140. begin
  141.   si = ScriptInterpreter.new
  142.   si.run
  143. end
复制代码
使用方法:插入mian之前

使用人群:经常出错的人,并且喜欢debug的人。

强烈推荐问问题时候使用,在提问的时候仅仅说一声“SyntaxError是怎么回事?”
一般是不会有人知道的。这个脚本会更加详尽的列出错误可能存在的原因,即方便于问又方便于答。而且错误已经保存在Backtrace.txt里(默认,可以自己改),省去了截图的麻烦。


截图:

“我推荐你一个游戏吧,avg的,剧情特感人”
“我擦,都是文字图片的游戏有啥好玩的,连个战斗都没有!”
“我推荐你一个游戏吧,rpg的,战斗也新颖”
“我擦,怎么米有作i弊器?“
”你不是喜欢战斗么?”
“不,我是剧情党!!”

继续阅读请点击
http://rpg.blue/blog-53316-10027.html

Lv1.梦旅人

风雪夜不归人

梦石
0
星屑
50
在线时间
276 小时
注册时间
2006-3-7
帖子
6721

贵宾

2
发表于 2008-2-24 19:34:57 | 只看该作者
好象很不错~~~支持一个
有些人,到了七八月份就会诈尸。
宫斗,是女生永远的爱。
冷门,是本人不变的欲。
作弊,是玩家自由的痛。
练级,是橙光割舍的情。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
145
在线时间
128 小时
注册时间
2005-10-22
帖子
1441

贵宾

3
发表于 2008-2-24 22:55:20 | 只看该作者
貌似是好东西{/se}
唉 装X迟早被雷霹,有捧着的,就得有泼凉水的
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

名侦探小柯

梦石
0
星屑
3294
在线时间
3618 小时
注册时间
2006-9-6
帖子
37400

开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

4
发表于 2008-2-24 23:03:41 | 只看该作者
脚本DEBUG……
回复 支持 反对

使用道具 举报

Lv1.梦旅人

史上最强粉丝

梦石
0
星屑
50
在线时间
9 小时
注册时间
2007-8-20
帖子
5574

贵宾

5
发表于 2008-2-25 01:14:13 | 只看该作者
这个好!立刻用到工程中!同时推荐莫妮卡和叮当整合他


还是看不明白……
回复 支持 反对

使用道具 举报

Lv1.梦旅人

万物创造者

梦石
0
星屑
54
在线时间
352 小时
注册时间
2008-2-15
帖子
2432
6
发表于 2008-2-25 03:14:41 | 只看该作者
很强大的东西- -
From mortal hope immortal power springs.
回复 支持 反对

使用道具 举报

Lv2.观梦者

天仙

梦石
0
星屑
610
在线时间
184 小时
注册时间
2008-4-15
帖子
5023

贵宾

7
发表于 2008-2-25 06:47:42 | 只看该作者
一个字:强{/qiang}

这样修改XP脚本也好用的多了
VA脚本开工中...
偷窃脚本1.0 - 已完成
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-8-23
帖子
539
8
发表于 2008-2-25 19:27:58 | 只看该作者
  1. #==============================================================================
  2. # ■ 容错脚本第3版                                              BY 轮回者
  3. #------------------------------------------------------------------------------
  4. #  本脚本基于星大叔的容错脚本第2版,区别只是“下手”的地方不同而已。
  5. #  说明请参看星大叔的容错脚本第2版。
  6. #==============================================================================

  7. $need_file_bitmap = []
  8. if FileTest.exist?("log_bitmap.txt")
  9. f = File.open("./log_bitmap.txt","r")
  10. $need_file_bitmap = f.read.split(/\n/)
  11. f.close
  12. end

  13. module Graphics
  14. @transition = method("transition")
  15. def self.transition(*arg)
  16.    begin
  17.      @transition.call(*arg)
  18.    rescue Errno::ENOENT
  19.      ary=[*arg]
  20.      filename=ary[1]
  21.      unless $need_file_bitmap.include?(filename)
  22.        $need_file_bitmap.push(filename)
  23.        f = File.open("./log_bitmap.txt","a")
  24.        f.write(filename + "\n")
  25.        f.close
  26.      end
  27.      @transition.call(ary[0])
  28.    end
  29. end
  30. end

  31. class Bitmap < Object
  32. alias ini initialize
  33. def initialize(*arg)
  34.    begin
  35.      ini(*arg)
  36.    rescue Errno::ENOENT
  37.      filename=[*arg][0]
  38.      unless $need_file_bitmap.include?(filename)
  39.        $need_file_bitmap.push(filename)
  40.        f = File.open("./log_bitmap.txt","a")
  41.        f.write(filename + "\n")
  42.        f.close
  43.      end
  44.      ini(32,32)
  45.    end
  46. end
  47. end

  48. $need_file_audio = []
  49. if FileTest.exist?("log_audio.txt")
  50. f = File.open("./log_audio.txt","r")
  51. $need_file_audio = f.read.split(/\n/)
  52. f.close
  53. end

  54. module Audio
  55. @me_play = method("me_play")
  56. def self.me_play(*arg)
  57.    begin
  58.      @me_play.call(*arg)
  59.    rescue Errno::ENOENT
  60.      filename=[*arg][0]
  61.      unless $need_file_audio.include?(filename)
  62.        $need_file_audio.push(filename)
  63.        f = File.open("./log_audio.txt","a")
  64.        f.write(filename + "\n")
  65.        f.close
  66.      end
  67.      me_stop
  68.    end
  69. end
  70. @bgm_play = method("bgm_play")
  71. def self.bgm_play(*arg)
  72.    begin
  73.      @bgm_play.call(*arg)
  74.    rescue Errno::ENOENT
  75.      filename=[*arg][0]
  76.      unless $need_file_audio.include?(filename)
  77.        $need_file_audio.push(filename)
  78.        f = File.open("./log_audio.txt","a")
  79.        f.write(filename + "\n")
  80.        f.close
  81.      end
  82.      bgm_stop
  83.    end
  84. end
  85. @se_play = method("se_play")
  86. def self.se_play(*arg)
  87.    begin
  88.      @se_play.call(*arg)
  89.    rescue Errno::ENOENT
  90.      filename=[*arg][0]
  91.      unless $need_file_audio.include?(filename)
  92.        $need_file_audio.push(filename)
  93.        f = File.open("./log_audio.txt","a")
  94.        f.write(filename + "\n")
  95.        f.close
  96.      end
  97.      se_stop
  98.    end
  99. end
  100. @bgs_play = method("bgs_play")
  101. def self.bgs_play(*arg)
  102.    begin
  103.      @bgs_play.call(*arg)
  104.    rescue Errno::ENOENT
  105.      filename=[*arg][0]
  106.      unless $need_file_audio.include?(filename)
  107.        $need_file_audio.push(filename)
  108.        f = File.open("./log_audio.txt","a")
  109.        f.write(filename + "\n")
  110.        f.close
  111.      end
  112.      bgs_stop
  113.    end
  114. end
  115. end
复制代码
横版卷轴ARPG制作中... 系统80% 素材95% 剧情1%.... 有脚本问题随时吼我- -(被T出)
回复 支持 反对

使用道具 举报

Lv1.梦旅人

月下可怜人

梦石
0
星屑
50
在线时间
10 小时
注册时间
2005-11-23
帖子
4085

第1届短篇游戏比赛亚军

9
发表于 2008-2-26 21:27:22 | 只看该作者
这个东西很方便啊,记得RUBY似乎有个可以直接回溯栈轨迹的方法,不是很清楚了.
纵然千里外,我等雁归来。
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
270
在线时间
1373 小时
注册时间
2005-10-16
帖子
5113

贵宾

10
发表于 2008-3-3 00:21:26 | 只看该作者
这个功能真不错~
看到了华丽的正则表达式,头疼......
我只个搬答案的
叔叔我已经当爹了~
婚后闪人了……
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-10 02:23

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表