Project1

标题: VX转ACE出现无法勾掉save_game模块函数 [打印本页]

作者: 流川枫    时间: 2012-7-3 13:20
标题: VX转ACE出现无法勾掉save_game模块函数
本帖最后由 流川枫 于 2012-7-7 19:34 编辑

RUBY 代码复制
  1. module DataManager
  2.   # 写入两个全局变量
  3.   alias original_le_save_game save_game
  4.   def self.save_game(index)
  5.     self.save_game(index)
  6.     Marshal.dump($le_run,file)
  7.     Marshal.dump($le_close_table,file)
  8.   end
  9. end


提示
Script '' line 317: NameError occurred.

undefined method `save_game' for module `DataManager'

不过确实有这个模块函数的呢啊
作者: Sylvania    时间: 2012-7-3 17:50
  1. module A
  2.   def p_a
  3.     p "a"
  4.   end
  5.   alias 打印a p_a
  6. end
  7. B = A
  8. include B
  9. p_a #=>"a"
  10. 打印a #=>"a"
复制代码

作者: 流川枫    时间: 2012-7-3 18:28
Sylvania 发表于 2012-7-3 17:50

你的代码虽然可以运行正确,但是问题不在于此。

存档的代码是在
alias original_le_save_game save_game
这行就报错,就好比你的
alias 打印a p_a
所以下面的代码都无法运行。
作者: 流川枫    时间: 2012-7-3 19:05
Sylvania 发表于 2012-7-3 17:50
  1. module A
  2.       def self.p_a
  3.         p "a"
  4.       end
  5.       alias 打印a p_a
  6.     end
  7.     B = A
  8.     include B
  9.     p_a #=>"a"
  10.     打印a #=>"a"
复制代码
你运行下这个代码就知道了
作者: Sylvania    时间: 2012-7-3 19:06
本帖最后由 Sylvania 于 2012-7-3 19:17 编辑

module 只是把一堆方法打个包,给予一个命名空间而已,在脚本一开始运行时一定会逐行运行一遍(可以理解为class的实例化)
“alias original_le_save_game save_game”前文没有定义过“save_game”怎么起别名?儿子都没出生呐,就在准备改名字了?

再给你一个例子:
RUBY 代码复制
  1. module A
  2.   def A
  3.     p "B"
  4.   end
  5.   alias B A
  6.   class A
  7.     def initialize
  8.       p "A"
  9.     end
  10.   end
  11. end
  12. include A
  13. A::A.new
  14. A.B

作者: 流川枫    时间: 2012-7-3 19:36
Sylvania 发表于 2012-7-3 19:06
module 只是把一堆方法打个包,给予一个命名空间而已,在脚本一开始运行时一定会逐行运行一遍(可以理解为c ...

你没写过ACE的存档脚本所以
作者: Sylvania    时间: 2012-7-3 20:26
呵呵,你知道我写过多少 Ruby 代码吗?好话不听,那就请你慢慢参悟吧,解决了不妨告知在下一声
作者: 流川枫    时间: 2012-7-3 20:37
Sylvania 发表于 2012-7-3 20:26
呵呵,你知道我写过多少 Ruby 代码吗?好话不听,那就请你慢慢参悟吧,解决了不妨告知在下一声 ...
  1. module A
  2.       def self.A
  3.         p "B"
  4.       end
  5.       alias B A
  6.       class A
  7.         def initialize
  8.           p "A"
  9.         end
  10.       end
  11.     end
  12.     include A
  13.     A::A.new
  14.     A.B
复制代码
如果把你的代码改成ACE的就提示以下错误
Script '' line 5: NameError occurred.

undefined method `A' for module `A'
作者: Sylvania    时间: 2012-7-3 20:47
本帖最后由 Sylvania 于 2012-7-3 20:47 编辑

我发的代码就是要不加那个 self ,如果不想 include 可以在前面声明 module_function
模块中带有 self 的方法无法起别名,这是我的结论
作者: 流川枫    时间: 2012-7-3 21:23
  1. #==============================================================================
  2. # ■ DataManager
  3. #------------------------------------------------------------------------------
  4. #  处理存档。
  5. #==============================================================================
  6. module DataManager
  7.   # 写入两个全局变量
  8.   def self.save_game_without_rescue(index)
  9.     File.open(make_filename(index), "wb") do |file|
  10.       $game_system.on_before_save
  11.       Marshal.dump(make_save_header, file)
  12.       Marshal.dump(make_save_contents, file)
  13.       @last_savefile_index = index
  14.       Marshal.dump($le_run,file)
  15.       Marshal.dump($le_close_table,file)
  16.     end
  17.     return true
  18.   end
  19.   def self.load_game_without_rescue(index)
  20.     File.open(make_filename(index), "rb") do |file|
  21.       Marshal.load(file)
  22.       extract_save_contents(Marshal.load(file))
  23.       reload_map_if_updated
  24.       @last_savefile_index = index
  25.       $le_run         = Marshal.load(file)
  26.       $le_close_table = Marshal.load(file)
  27.     end
  28.     return true
  29.   end
  30. end
复制代码
如果不考虑兼容问题,一开始就知道怎么做了。
但问题还是在于ACE的这种设计貌似更加让脚本容易冲突了呢呀
作者: 晴兰    时间: 2012-7-7 06:08
提示: 作者被禁止或删除 内容自动屏蔽
作者: orzfly    时间: 2012-7-7 06:33
  1. module DataManager
  2.   def self.a # 这句其实是在 这里的 self 对象中定义了。
  3.   end
  4.   class << self  # eigen-class,打开 self 操作
  5.     alias b a
  6.     def c
  7.     end
  8.   end
  9. end
复制代码


另外 7 楼,请收回你的傲气。连 eigen-class 都不知道我都不好意思说我是写 Ruby 的。






欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1