Project1

标题: 请问$game_temp.battle_proc的作用 [打印本页]

作者: kvkv97    时间: 2026-1-14 23:46
标题: 请问$game_temp.battle_proc的作用
  #--------------------------------------------------------------------------
  # ● 战斗处理
  #--------------------------------------------------------------------------
  def command_301
    # 如果不是无效的队伍
    if $data_troops[@parameters[0]] != nil
      # 设置中断战斗标志
      $game_temp.battle_abort = true
      # 设置战斗调用标志
      $game_temp.battle_calling = true
      $game_temp.battle_troop_id = @parameters[0]
      $game_temp.battle_can_escape = @parameters[1]
      $game_temp.battle_can_lose = @parameters[2]
      # 设置返回调用
      current_indent = @list[@index].indent
      $game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n}

    end
    # 推进索引
    @index += 1
    # 结束
    return false
  end




请问: $game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n}的作用是什么?@branch等于{0=>0}战斗胜利返回调用有什么作用?

作者: 无忧谷主幻    时间: 2026-1-15 06:20
本帖最后由 无忧谷主幻 于 2026-1-15 06:24 编辑

简单来说,就是战斗事件后的后续条件分支,判断不同的战斗结果(如胜利、失败、逃跑),以此执行不同的事件
@branch等于{0=>0}应该就是判定为战斗胜利,然后执行胜利对应的剧情

作者: kvkv97    时间: 2026-1-15 23:46
  #--------------------------------------------------------------------------
  # ● 战斗结束
  #     result : 結果 (0:胜利 1:失败 2:逃跑)
  #--------------------------------------------------------------------------
  def battle_end(result)
   
    # 清除战斗中标志
    $game_temp.in_battle = false
    # 清除全体同伴的行动
    $game_party.clear_actions
    # 解除战斗用状态
    for actor in $game_party.actors
      actor.remove_states_battle
    end
    # 清除敌人
    $game_troop.enemies.clear
    # 调用战斗返回
    if $game_temp.battle_proc != nil
      $game_temp.battle_proc.call(result)
    end
  end
为什么在P  battle_end(0) 的时候,返回值是0 而不是{0=>0}
作者: 灯笼菜刀王    时间: 2026-1-24 17:50
本帖最后由 灯笼菜刀王 于 2026-1-24 17:56 编辑

F1查看Proc 这一类的解释

用个栗子, 它就是"指令仓库", 生成实例的时候, 把一段脚本指令"存"进去, 然后在需要的地方"取"出来(#call)  

所以, 在 $game_temp.battle_proc.call(result) 这里就是取出它保存的指令, 同时赋予参数0, 所以这里实际运行的其实是之前保存的 @branch[current_indent] = 0  这段脚本




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