| 
 
| 赞 | 0 |  
| VIP | 0 |  
| 好人卡 | 0 |  
| 积分 | 1 |  
| 经验 | 1825 |  
| 最后登录 | 2014-4-20 |  
| 在线时间 | 32 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间32 小时注册时间2010-7-7帖子18 | 
| 本帖最后由 okasssss 于 2012-7-12 17:37 编辑 
 
 在天干宝典的面看到的脚本
 
 
 有问题的地方是弟16和37行,在定义refresh函数中,产生了一个@total_sec变量,在update函数中又用到了它,这个@total_sec变量的作用域不是refresh吗?为什么在update还能用?复制代码class Window_1 < Window_Base 
#BLOCK 1 
def initialize 
super(0, 0, 640,100) 
self.contents = Bitmap.new(width-32, height-32) 
self.contents.font.name = "黑体" 
self.contents.font.size = 20 
refresh 
end 
#BLOCK 2 
def refresh 
self.contents.clear 
self.contents.font.color = text_color(6) 
self.contents.draw_text(0, 0, 100, 32, "游戏时间:") 
#显示游戏时间 (从 Window_PlayTime中Copy来) 
@total_sec = Graphics.frame_count / Graphics.frame_rate 
hour = @total_sec / 60 / 60 
min = @total_sec / 60 % 60 
sec = @total_sec % 60 
text = sprintf("%02d:%02d:%02d", hour, min, sec) 
self.contents.font.color = normal_color 
self.contents.draw_text(100, 0, 120, 32, text) 
# 结束显示游戏时间的编码 
#BLOCK 3 
self.contents.font.color = text_color(6) 
self.contents.draw_text(250, 0, 50, 32, "金钱:") 
self.contents.font.color = text_color(0) 
self.contents.draw_text(305, 0, 100, 32, $game_party.gold.to_s) 
#BLOCK 4 
self.contents.font.color = text_color(6) 
self.contents.draw_text(400, 0, 100, 32, "地图 ID:") 
self.contents.font.color = text_color(0) 
self.contents.draw_text(480, 0, 100, 32, $game_map.map_id.to_s) 
end 
#BLOCK 5 
def update 
if Graphics.frame_count / Graphics.frame_rate != @total_sec 
refresh 
end 
end 
 | 
 |