查看: 1389|回复: 1

[已经解决] 脚本错误

[复制链接]
梦石
0
星屑
319
在线时间
209 小时
注册时间
2007-6-23
回帖
33
发表于 2013-10-4 10:38:10 | 显示全部楼层 |阅读模式

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

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

×
  1. $game_variables[2]=0 if $game_variables[2]==nil   
  2.   $c==$game_variables[2]
复制代码
这个脚本代码在运行游戏时出现错误,这是图片
哪里出错了?
QQ截图20131004103643.jpg

百合控

梦石
0
星屑
6548
在线时间
1275 小时
注册时间
2013-8-21
回帖
3522

开拓者

发表于 2013-10-4 11:23:56 | 显示全部楼层
1.$game_variables 在游戏运行前是未定义的,所以不能再游戏运行前操作
2.$c==$game_variables[2]这句话也错了……应该是=而不是==
######################################
详细说明:
  1. #==============================================================================
  2. # ■ Game_Variables
  3. #------------------------------------------------------------------------------
  4. #  处理变量的类。本质上是套了个壳的 Array 。本类的实例请参考 $game_variables 。
  5. #==============================================================================
复制代码
没错,是有这个,但是$game_variables在哪里呢?
  1. #==============================================================================
  2. # ■ DataManager
  3. #------------------------------------------------------------------------------
  4. #  数据库和游戏实例的管理器。所有在游戏中使用的全局变量都在这里初始化。
  5. #==============================================================================
复制代码
  1.   #--------------------------------------------------------------------------
  2.   # ● 生成各种游戏对象
  3.   #--------------------------------------------------------------------------
  4.   def self.create_game_objects
  5.     $game_temp          = Game_Temp.new
  6.     $game_system        = Game_System.new
  7.     $game_timer         = Game_Timer.new
  8.     $game_message       = Game_Message.new
  9.     $game_switches      = Game_Switches.new
  10.     $game_variables     = Game_Variables.new #找到你了!
  11.     $game_self_switches = Game_SelfSwitches.new
  12.     $game_actors        = Game_Actors.new
  13.     $game_party         = Game_Party.new
  14.     $game_troop         = Game_Troop.new
  15.     $game_map           = Game_Map.new
  16.     $game_player        = Game_Player.new
  17.   end
复制代码
这个create_game_objects又是谁调用的呢?
  1.   #--------------------------------------------------------------------------
  2.   # ● 初始化模块
  3.   #--------------------------------------------------------------------------
  4.   def self.init
  5.     @last_savefile_index = 0
  6.     load_database
  7.     create_game_objects
  8.     setup_battle_test if $BTEST
  9.   end
复制代码
好吧,原来是这样的,可是init不会无缘无故的来
  1. #==============================================================================
  2. # ■ SceneManager
  3. #------------------------------------------------------------------------------
  4. #  场景切换的管理器。RGSS3 内置了新功能,在使用 call 方法切换新场景时,可以
  5. #   用 return 方法返回上一个场景。
  6. #==============================================================================
复制代码
  1.   #--------------------------------------------------------------------------
  2.   # ● 运行
  3.   #--------------------------------------------------------------------------
  4.   def self.run
  5.     DataManager.init
  6.     Audio.setup_midi if use_midi?
  7.     [url=home.php?mod=space&uid=420706]@Scene[/url] = first_scene_class.new
  8.     @scene.main while @scene
  9.   end
复制代码
原来如此,可是同理,run不会自己执行
  1. #==============================================================================
  2. # ■ Main
  3. #------------------------------------------------------------------------------
  4. #  各种定义结束后,从这里开始实际运行。
  5. #==============================================================================

  6. rgss_main { SceneManager.run }
复制代码
好吧,原来在所有脚本之后才有这个
##################
在脚本的最后才会生成$game_variables,所以你在它之前使用$game_variables必然是会出错的

评分

参与人数 1梦石 +1 收起 理由
熊喵酱 + 1 精品文章

查看全部评分

萌新瑟瑟发抖
看到我请叫我去干活
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部