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

Project1

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

[已经解决] 禁止卷动脚本更新Scene_Map时报错

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24287
在线时间
5047 小时
注册时间
2016-3-8
帖子
1618
跳转到指定楼层
1
发表于 2021-2-1 00:00:25 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
125星屑
本帖最后由 alexncf125 于 2021-2-1 00:27 编辑

这脚本用F9开啟3号变量, 回地图, 再用F9关闭3号变量, 最后回地图报错disposed window/disposed tilemap
我只找到原因出自这三句:
scene = SceneManager.scene
scene.update_basic
scene.instance_variable_get(:@spriteset).update

平常用事件开关3,4号变量是会没事, 我就只想了解一下F9的BUG能修好的不?
脚本

最佳答案

查看完整内容

这波是脚本语言的灵活性以及脚本作者的偷懒二者共同背锅。 因为不到运行时不会检查方法能否运行,所以如果不出现预想以外的使用场景,就没事。 但是这也为脚本制作者提供了一个偷懒的机会,那就是——我可以少加异常处理、错误判断, 反正我只保证在xx条件下不出错,使用脚本出错了就怪使用者操作太骚。 在这里就很明显,大部分的Scene是没有Spriteset的(实际上,也就Scene_Map和Scene_Battle是有的) 所以取@spriteset这个 ...

Lv5.捕梦者

梦石
0
星屑
24287
在线时间
5047 小时
注册时间
2016-3-8
帖子
1618
来自 2楼
 楼主| 发表于 2021-2-1 00:22:48 | 只看该作者
本帖最后由 alexncf125 于 2021-2-1 23:18 编辑
试著插入这段

和把那段改成
last_scene = SceneManager.last_scene
return if last_scene.is_a?(Scene_Debug)
scene = SceneManager.scene
scene.update_basic
scene.instance_variable_get(:@spriteset).update

好像能解決掉问题

能请大佬们指教一下, 原先那两句有啥用途??是必须写的么??
我这样用return跳过它们没问题吧
回复

使用道具 举报

Lv5.捕梦者

梦石
10
星屑
39440
在线时间
1914 小时
注册时间
2010-11-14
帖子
3315

R考场第七期纪念奖

3
发表于 2021-2-1 00:00:26 | 只看该作者
本帖最后由 KB.Driver 于 2021-2-1 22:48 编辑
alexncf125 发表于 2021-2-1 00:22
[fold=试著插入这段]module SceneManager

  @last_scene = nil


这波是脚本语言的灵活性以及脚本作者的偷懒二者共同背锅。

因为不到运行时不会检查方法能否运行,所以如果不出现预想以外的使用场景,就没事。

但是这也为脚本制作者提供了一个偷懒的机会,那就是——我可以少加异常处理、错误判断,
反正我只保证在xx条件下不出错,使用脚本出错了就怪使用者操作太骚。

在这里就很明显,大部分的Scene是没有Spriteset的(实际上,也就Scene_Map和Scene_Battle是有的)
所以取@spriteset这个违反OOP的投机写法(虽然ruby就是很灵活,就是可以这样写,但不代表它是好的)
如果不用if语句控制条件或者用begin...end的异常处理包裹,它就是很脆弱的(不具健壮性,robust)

至于出错的原因,个人推理如下:
修改$game_variables(开关也是一样),会触发on_change方法,
从而使$game_map.need_refresh = true,令Game_Map触发refresh方法。


在Scene_Map或者Scene_Battle中这样做没有影响,因为它们有@spriteset变量

但是在Scene_Debug里修改变量,一样触发Game_Map的refresh,
你所用的脚本又修改了这个refresh,让它对当前场景的@spriteset进行更新
这个变量在Scene_Debug里并不存在,这就产生错误了。

===================================================================

这给我们带来什么启示呢?
1、写法投机的脚本往往不具备健壮性,建议自己用或者给身边人玩玩就好,拿出来大规模分享就不必了。
2、如果真要大规模分享,请多从使用者的角度考虑,提高兼容性,减少代码出错的可能。


评分

参与人数 2星屑 +60 +1 收起 理由
fux2 + 60 认可答案
alexncf125 + 1 万分感谢!!!!!!!!!!.

查看全部评分

用头画头像,用脚写脚本
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24287
在线时间
5047 小时
注册时间
2016-3-8
帖子
1618
4
 楼主| 发表于 2021-2-2 00:44:41 | 只看该作者
本帖最后由 alexncf125 于 2021-2-26 17:00 编辑

万分感谢!!!!!!!!!!

经过日历大佬的指点, 终于改到没bug了~

RUBY 代码复制
  1. #==============================================================================
  2. # ★スクロール禁止 ver1.0 by USK
  3. #------------------------------------------------------------------------------
  4. # ・特定のスイッチがオンのときスクロールを禁止します。
  5. #==============================================================================
  6. =begin
  7. ・21行目のFixDisplayFlagVで設定した番号のスイッチがオンのとき
  8.   縦スクロールが禁止されます。
  9. ・22行目のFixDisplayFlagHで設定した番号のスイッチがオンのとき
  10.   横スクロールが禁止されます。
  11. =end
  12. ##########
  13. module SceneManager
  14.  
  15.   @last_scene = nil
  16.  
  17.   def self.last_scene
  18.     @last_scene
  19.   end
  20.  
  21.   class << self; alias last_scene_call call; end
  22.   def self.call(scene_class)
  23.     @last_scene = @scene
  24.     last_scene_call(scene_class)
  25.   end
  26.  
  27.   def self.return
  28.     @last_scene = @scene
  29.     @scene = @stack.pop
  30.   end
  31.  
  32.   def self.refresh_scene
  33.     @last_scene = @scene
  34.   end
  35.  
  36. end
  37. ##########
  38. #==============================================================================
  39. # ■ Game_Map
  40. #==============================================================================
  41.  
  42. class Game_Map
  43.   #--------------------------------------------------------------------------
  44.   # ● 設定
  45.   #--------------------------------------------------------------------------
  46.   FixDisplayFlagV = 3 #禁止Y轴卷动的开关编号
  47.   FixDisplayFlagH = 4 #禁止X轴卷动的开关编号
  48.   #--------------------------------------------------------------------------
  49.   # ●
  50.   #--------------------------------------------------------------------------
  51.   alias :fix_display_scroll_down  :scroll_down
  52.   alias :fix_display_scroll_left  :scroll_left
  53.   alias :fix_display_scroll_right :scroll_right
  54.   alias :fix_display_scroll_up    :scroll_up
  55.   alias :fix_display_refresh      :refresh
  56.   alias :fix_display_valid?       :valid?
  57.   #--------------------------------------------------------------------------
  58.   # ●
  59.   #--------------------------------------------------------------------------
  60.   def fix_display?
  61.     $game_switches[FixDisplayFlagV] || $game_switches[FixDisplayFlagH]
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ●
  65.   #--------------------------------------------------------------------------
  66.   def need_centering?
  67.     ret = !fix_display? &&
  68.           SceneManager.scene.is_a?(Scene_Map) &&
  69.           @on_fix_display
  70.     @on_fix_display = fix_display?
  71.     ret
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ●
  75.   #--------------------------------------------------------------------------
  76.   def centering
  77.     div = 20
  78.     x = @display_x
  79.     dx = $game_player.x - (Graphics.width / 32 - 1) / 2.0 - x
  80.     dx /= div
  81.     y = @display_y
  82.     dy = $game_player.y - (Graphics.height / 32 - 1) / 2.0 - y
  83.     dy /= div
  84.     div.times do
  85.       set_display_pos(x, y)
  86.       x += dx
  87.       y += dy
  88.       scene = SceneManager.scene
  89.       scene.update_basic
  90.       scene.instance_variable_get(:@spriteset).update
  91.     end
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● リフレッシュ
  95.   #--------------------------------------------------------------------------
  96.   def refresh
  97.     ##########
  98.     last_scene = SceneManager.last_scene
  99.     if last_scene.is_a?(Scene_Debug)
  100.       SceneManager.refresh_scene
  101.       return fix_display_refresh
  102.     end
  103.     ##########
  104.     centering if need_centering?
  105.     fix_display_refresh
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● 下にスクロール
  109.   #--------------------------------------------------------------------------
  110.   def scroll_down(distance)
  111.     fix_display_scroll_down(distance) unless $game_switches[FixDisplayFlagV]
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # ● 左にスクロール
  115.   #--------------------------------------------------------------------------
  116.   def scroll_left(distance)
  117.     fix_display_scroll_left(distance) unless $game_switches[FixDisplayFlagH]
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 右にスクロール
  121.   #--------------------------------------------------------------------------
  122.   def scroll_right(distance)
  123.     fix_display_scroll_right(distance) unless $game_switches[FixDisplayFlagH]
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 上にスクロール
  127.   #--------------------------------------------------------------------------
  128.   def scroll_up(distance)
  129.     fix_display_scroll_up(distance) unless $game_switches[FixDisplayFlagV]
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 有効座標判定
  133.   #--------------------------------------------------------------------------
  134.   def valid?(x, y)
  135.     ret = fix_display_valid?(x, y)
  136.     if $game_switches[FixDisplayFlagV]
  137.       ret &&= y >= @display_y && y < @display_y + (Graphics.height >> 5)
  138.     end
  139.     if $game_switches[FixDisplayFlagH]
  140.       ret &&= x >= @display_x && x < @display_x + (Graphics.width >> 5)
  141.     end
  142.     ret
  143.   end
  144. end
  145. ##########
  146. class Scene_Map < Scene_Base
  147.   alias :fix_display_start :start
  148.   def start
  149.     fix_display_start
  150.     $game_map.centering if $game_map.need_centering?
  151.   end
  152. end
  153. ##########

用两个##########包裹的是新增的內容
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-26 14:05

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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