Project1

标题: 数组载入单元时用什么括号? [打印本页]

作者: 876加几    时间: 2013-10-4 21:02
标题: 数组载入单元时用什么括号?
由于数组的附加码搞不懂,所以总是说脚本“Window_Task”124行“[]”出现NoMethodError。
但是这本来就是对的呀!
好吧,贴原脚本:
  1. #==============================================================================
  2. # ■ Game_Temp
  3. #------------------------------------------------------------------------------
  4. #  在没有存档的情况下,处理临时数据的类。这个类的实例请参考
  5. # $game_temp 。
  6. #==============================================================================

  7. class Game_Temp
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_accessor :map_bgm                  # 地图画面 BGM (战斗时记忆用)
  12.   attr_accessor :message_text             # 信息文章
  13.   attr_accessor :message_proc             # 信息 返回调用 (Proc)
  14.   attr_accessor :choice_start             # 选择项 开始行
  15.   attr_accessor :choice_max               # 选择项 项目数
  16.   attr_accessor :choice_cancel_type       # 选择项 取消的情况
  17.   attr_accessor :choice_proc              # 选择项 返回调用 (Proc)
  18.   attr_accessor :num_input_start          # 输入数值 开始行
  19.   attr_accessor :num_input_variable_id    # 输入数值 变量 ID
  20.   attr_accessor :num_input_digits_max     # 输入数值 位数
  21.   attr_accessor :message_window_showing   # 显示信息窗口
  22.   attr_accessor :common_event_id          # 公共事件 ID
  23.   attr_accessor :in_battle                # 战斗中的标志
  24.   attr_accessor :battle_calling           # 调用战斗的标志
  25.   attr_accessor :battle_troop_id          # 战斗 队伍 ID
  26.   attr_accessor :battle_can_escape        # 战斗中 允许逃跑 ID
  27.   attr_accessor :battle_can_lose          # 战斗中 允许失败 ID
  28.   attr_accessor :battle_proc              # 战斗 返回调用 (Proc)
  29.   attr_accessor :battle_turn              # 战斗 回合数
  30.   attr_accessor :battle_event_flags       # 战斗 事件执行执行完毕的标志
  31.   attr_accessor :battle_abort             # 战斗 中断标志
  32.   attr_accessor :battle_main_phase        # 战斗 状态标志
  33.   attr_accessor :battleback_name          # 战斗背景 文件名
  34.   attr_accessor :forcing_battler          # 强制行动的战斗者
  35.   attr_accessor :shop_calling             # 调用商店的标志
  36.   attr_accessor :shop_goods               # 商店 商品列表
  37.   attr_accessor :name_calling             # 输入名称 调用标志
  38.   attr_accessor :name_actor_id            # 输入名称 角色 ID
  39.   attr_accessor :name_max_char            # 输入名称 最大字数
  40.   attr_accessor :menu_calling             # 菜单 调用标志
  41.   attr_accessor :menu_beep                # 菜单 SE 演奏标志
  42.   attr_accessor :save_calling             # 存档 调用标志
  43.   attr_accessor :debug_calling            # 调试 调用标志
  44.   attr_accessor :player_transferring      # 主角 场所移动标志
  45.   attr_accessor :player_new_map_id        # 主角 移动目标地图 ID
  46.   attr_accessor :player_new_x             # 主角 移动目标 X 坐标
  47.   attr_accessor :player_new_y             # 主角 移动目标 Y 坐标
  48.   attr_accessor :player_new_direction     # 主角 移动目标 朝向
  49.   attr_accessor :transition_processing    # 过渡处理中标志
  50.   attr_accessor :transition_name          # 过渡 文件名
  51.   attr_accessor :gameover                 # 游戏结束标志
  52.   attr_accessor :to_title                 # 返回标题画面标志
  53.   attr_accessor :last_file_index          # 最后存档的文件编号
  54.   attr_accessor :debug_top_row            # 调试画面 保存状态用
  55.   attr_accessor :debug_index              # 调试画面 保存状态用
  56.   attr_accessor :new_task_name            # 新任务 名称
  57.   attr_accessor :new_task_help            # 新任务 帮助文字
  58.   attr_accessor :new_task_gold            # 新任务 奖励金钱
  59.   attr_accessor :new_task_items           # 新任务 奖励物品
  60.   attr_accessor :new_task_weapons         # 新任务 奖励武器
  61.   attr_accessor :new_task_armors          # 新任务 奖励防具
  62.   attr_accessor :tasks                    # 已有的任务个数
  63.   attr_accessor :new_task_item_num        # 新任务 物品奖励数量
  64.   attr_accessor :new_task_weapon_num      # 新任务 武器奖励数量
  65.   attr_accessor :new_task_armor_num       # 新任务 防具奖励数量
  66.   attr_accessor :new_task_difficulty
  67.   #--------------------------------------------------------------------------
  68.   # ● 初始化对像
  69.   #--------------------------------------------------------------------------
  70.   def initialize
  71.     @map_bgm = nil
  72.     @message_text = nil
  73.     @message_proc = nil
  74.     @choice_start = 99
  75.     @choice_max = 0
  76.     @choice_cancel_type = 0
  77.     @choice_proc = nil
  78.     @num_input_start = 99
  79.     @num_input_variable_id = 0
  80.     @num_input_digits_max = 0
  81.     @message_window_showing = false
  82.     @common_event_id = 0
  83.     @in_battle = false
  84.     @battle_calling = false
  85.     @battle_troop_id = 0
  86.     @battle_can_escape = false
  87.     @battle_can_lose = false
  88.     @battle_proc = nil
  89.     @battle_turn = 0
  90.     @battle_event_flags = {}
  91.     @battle_abort = false
  92.     @battle_main_phase = false
  93.     @battleback_name = ''
  94.     @forcing_battler = nil
  95.     @shop_calling = false
  96.     @shop_id = 0
  97.     @name_calling = false
  98.     @name_actor_id = 0
  99.     @name_max_char = 0
  100.     @menu_calling = false
  101.     @menu_beep = false
  102.     @save_calling = false
  103.     @debug_calling = false
  104.     @player_transferring = false
  105.     @player_new_map_id = 0
  106.     @player_new_x = 0
  107.     @player_new_y = 0
  108.     @player_new_direction = 0
  109.     @transition_processing = false
  110.     @transition_name = ""
  111.     @gameover = false
  112.     @to_title = false
  113.     @last_file_index = 0
  114.     @debug_top_row = 0
  115.     @debug_index = 0
  116.     @new_task_name = ""
  117.     @new_task_help = ""
  118.     @new_task_gold = ""
  119.     @new_task_items = nil
  120.     @new_task_weapons = nil
  121.     @new_task_armors = nil
  122.     @tasks = 0
  123.     @new_task_item_num = 0
  124.     @new_task_weapon_num = 0
  125.     @new_task_armor_num = 0
  126.     @new_task_difficulty = 1
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 生成新任务(在Scene_Task的内部使用)
  130.   #--------------------------------------------------------------------------
  131.   def new_task(name, help, difficulty = 1, gold = 0, items = nil, weapons = nil, armors = nil, item_num = 1, weapon_num = 1, armor_num = 1)
  132.     # 实例变量的改变
  133.     @new_task_name = name
  134.     @new_task_help = help
  135.     @new_task_gold = gold
  136.     @new_task_items = items
  137.     @new_task_weapons = weapons
  138.     @new_task_armors = armors
  139.     @new_task_item_num = item_num
  140.     @new_task_weapon_num = weapon_num
  141.     @new_task_armor_num = armor_num
  142.     @new_task_difficulty = difficulty
  143.     @tasks += 1
  144.     # 保存数据(载入数组)
  145.     if $task_name == nil
  146.       $task_name = [@new_task_name]
  147.       $task_command_name = [@new_task_name]
  148.       $task_help = [@new_task_help]
  149.       $task_gold = [@new_task_gold]
  150.       $task_items = [@new_task_items]
  151.       $task_weapons = [@new_task_weapons]
  152.       $task_armors = [@new_task_armors]
  153.       $task_item_num = [@new_task_item_num]
  154.       $task_weapon_num = [@new_task_weapon_num]
  155.       $task_armor_num = [@new_task_armor_num]
  156.       $task_difficulty = [@new_task_difficulty]
  157.     else
  158.       $task_name[@tasks] = @new_task_name
  159.       $task_command_name[@tasks] = @new_task_name
  160.       $task_help[@tasks] = @new_task_help
  161.       $task_gold[@tasks] = @new_task_gold
  162.       $task_items[@tasks] = @new_task_items
  163.       $task_weapons[@tasks] = @new_task_weapons
  164.       $task_armors[@tasks] = @new_task_armors
  165.       $task_item_num[@tasks] = @new_task_item_num
  166.       $task_weapon_num[@tasks] = @new_task_weapon_num
  167.       $task_armor_num[@tasks] = @new_task_armor_num
  168.       $task_difficulty[@tasks] = @new_task_difficulty
  169.     end                     
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ● 完成任务(在Scene_Task的内部使用)
  173.   #--------------------------------------------------------------------------
  174.   def final_task(id)
  175.     # 如果任务没有失败
  176.     unless $task_name.include?("(已失败)")
  177.       # 算出数组中的id
  178.       id = id - 1
  179.       # 修改数组数据
  180.       $task_command_name[id] = $task_command_name[id] + "(已完成)"
  181.       $task_help[id] = $task_help[id] + "(已完成)"
  182.       # 获得任务奖励
  183.       unless $task_gold[id] == 0
  184.         $game_party.gain_gold($task_gold[id])
  185.       end
  186.       unless $task_items[id] == nil
  187.         $game_party.gain_item($task_items[id], $task_item_num[@tasks])
  188.       end
  189.       unless $task_weapons[id] == nil
  190.         $game_party.gain_weapon($task_weapons[id], $task_weapon_num[@tasks])
  191.       end
  192.       unless $task_armors[id] == nil
  193.         $game_party.gain_armor($task_armors[id], $task_armor_num[@tasks])
  194.       end
  195.     end
  196.   end
  197.   #------------------------------------------------------------------------
  198.   # 失败任务(啊啊啊!)
  199.   #------------------------------------------------------------------------
  200.   def lose_task(id)
  201.     unless $task_name.include?("(已完成)")
  202.       $task_command_name[id] = $task_command_name[id] + "(已失败)"
  203.       $task_help[id] = $task_help[id] + "(已失败)"
  204.     end
  205.   end
  206. end
复制代码
  1. #==============================================================================
  2. # ■ Window_Task
  3. #------------------------------------------------------------------------------
  4. #  显示任务的选择行窗口。
  5. #==============================================================================

  6. class Window_Task < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(0, 0, 640, 480 - 64)
  12.     if $game_temp.tasks == 0
  13.       @item_max = 1
  14.     else
  15.       @item_max = $game_temp.tasks
  16.     end
  17.     difficulty = nil
  18.     self.contents = Bitmap.new(width - 32, height - 32)
  19.     refresh
  20.     self.index = 0
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 刷新
  24.   #--------------------------------------------------------------------------
  25.   def refresh
  26.     self.contents.clear
  27.     if $game_temp.tasks == 0
  28.       @item_max = 1
  29.     else
  30.       @item_max = $game_temp.tasks
  31.     end
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 描绘项目
  35.   #     index : 项目编号
  36.   #     color : 文字色
  37.   #--------------------------------------------------------------------------
  38.   def draw_item(index,color)
  39.     self.contents.font.color = color
  40.     rect = Rect.new(4, 32 * index, 640 / 2 - 8, 32)
  41.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  42.     self.contents.draw_text(rect, $task_name[index])
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 项目无效化
  46.   #     index : 项目编号
  47.   #--------------------------------------------------------------------------
  48.   def disable_item(index)
  49.     draw_item(index, disabled_color)
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 刷新光标矩形
  53.   #--------------------------------------------------------------------------
  54.   def update_cursor_rect
  55.     if [url=home.php?mod=space&uid=370741]@Index[/url] < 0
  56.       self.cursor_rect.empty
  57.     else
  58.       self.cursor_rect.set(0, @index * 56, 320 - 8, 32)
  59.     end
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ● 拆分数组并显示内容
  63.   #--------------------------------------------------------------------------
  64.   def update
  65.     super
  66.     for i in 0...@item_max
  67.       x = 320 + 16
  68.       if self.index == i and $t == true and $task_command_name[self.index] == ""
  69.         $f = false
  70.         refresh
  71.         self.contents.font.color = system_color
  72.         self.contents.draw_text(x, 0, 100, 32, "任务名:")
  73.         self.contents.draw_text(x, 64, 100, 32, "难度:")
  74.         self.contents.draw_text(x, 112, 100, 32, "说明:")
  75.         if $task_gold[self.index] != 0
  76.           self.contents.draw_text(x, 176, 100, 32, "奖励金钱:")
  77.           y = 240
  78.         else
  79.           y = 208
  80.         end
  81.         if $task_items[self.index] != nil
  82.           self.contents.draw_text(x, y, 100, 32, "奖励物品:")
  83.         end
  84.         self.contents.font.color = normal_color
  85.         self.contents.draw_text(x, 32, 320 - 32, 32, $task_name[index])
  86.         self.contents.draw_text(x, 144, 280, 32, $task_help[index])
  87.         if $task_gold[self.index] != 0
  88.           self.contents.draw_text(x, 208, 100, 32, $task_gold[index])
  89.         end
  90.         if $task_items[self.index] != nil
  91.           draw_item_name($data_items[$task_items[index]], x, y + 32)
  92.         end
  93.         if $task_weapons[self.index] != nil
  94.           draw_item_name($data_weapons[$task_weapons[index]], x, y + 64)
  95.         end
  96.         if $task_armors[self.index] != nil
  97.           draw_item_name($data_armors[$task_armors[index]], x, y + 96)
  98.         end
  99.         #Moon = difficulty[self.index] / DIFFICULTY::System
  100.         #Star = difficulty[self.index] % DIFFICULTY::System
  101.         #Sun = Moon / DIFFICULTY::System
  102.         #Moon %= DIFFICULTY::System
  103.         #Space = DIFFICULTY::Space
  104.         #rect = Rect.new(0, 0, DIFFICULTY::Size, DIFFICULTY::Size)
  105.         #while Sun>0
  106.         #  self.contents.blt(x + Space, 96, Sun, rect)
  107.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Sun -= 1
  108.         #end
  109.         #while Moon>0
  110.         #  self.contents.blt(x + Space, 97, Moon, rect)
  111.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Moon -= 1
  112.         #end
  113.         #while Star>0
  114.         #  self.contents.blt(x + Space, 98, Star, rect)
  115.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Star -= 1
  116.         #end
  117.         text1 = "★" * $task_difficulty[self.index]
  118.         text2 = "☆" * (5 - $task_difficulty[index])
  119.         text = text1 + text2
  120.         self.contents.draw_text(x + 60, 64, 280, 32, text)
  121.       end
  122.     end
  123.     if $task_command_name[self.index] == ""
  124.       $f = true
  125.     end
  126.   end
  127. end
复制代码
数组载入单元时用什么括号?
作者: chd114    时间: 2013-10-4 21:19
当然是用{}啊···
作者: myownroc    时间: 2013-10-4 21:38
NoMethodError说明$task_command_name还不是一个数组。
应该在开始游戏时的
所有$game_xxx=…(这代码在Scene_Title里有)之后加上
$task_conmand_name=[]
使之成为一个空的数组
相应地,任务的存档读档的脚本也要做好
作者: 876加几    时间: 2013-10-4 21:48
myownroc 发表于 2013-10-4 21:38
NoMethodError说明$task_command_name还不是一个数组。
应该在开始游戏时的
所有$game_xxx=…(这代码在Scen ...

还是同样124行的“[]”患了NoMethodError
作者: 恐惧剑刃    时间: 2013-10-4 22:15
工程呢?没工程怎么回答?
那个恐怕不是主要问题吧
作者: 紫英晓狼1130    时间: 2013-10-5 09:47
获取这么多量推荐多分几个块,要不FPS下降什么的就出现了…




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