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

Project1

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

return的意思

 关闭 [复制链接]

Lv1.梦旅人

蚂蚁卡卡

梦石
0
星屑
116
在线时间
66 小时
注册时间
2007-12-16
帖子
3081
跳转到指定楼层
1
发表于 2009-6-8 23:34:58 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

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

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

x
def move
    if @wait_count > 0
       @wait_count -= 1
      return
    end
……

初始化里@wait_count = 5

问: if @wait_count > 0
       @wait_count -= 1
      return
    end
if 后面retrun的意思
返回,返回什么?
有什么作用?


版务信息:本贴由楼主自主结贴~
《隋唐乱》完整解密版点击进入
米兰,让我怎么说离开……

曾经我也是一个有志青年,直到我膝盖中了一箭……

《隋唐乱》博客地址

Lv1.梦旅人

蚂蚁卡卡

梦石
0
星屑
116
在线时间
66 小时
注册时间
2007-12-16
帖子
3081
2
 楼主| 发表于 2009-6-8 23:48:12 | 显示全部楼层
主要的是if 后面的return

好像我填1、2、3之类也能运行

if @wait_count > 0
       @wait_count -= 1
      return nil # 或者1、2、3之类的
end


如果这段代码不足以说明问题 我马上传工程




回35
那个 return 后面加什么也都还是"a"
为什么?
F1里的return有
return 12
return 1,2,3
能解释下么?
《隋唐乱》完整解密版点击进入
米兰,让我怎么说离开……

曾经我也是一个有志青年,直到我膝盖中了一箭……

《隋唐乱》博客地址
回复 支持 反对

使用道具 举报

Lv1.梦旅人

蚂蚁卡卡

梦石
0
星屑
116
在线时间
66 小时
注册时间
2007-12-16
帖子
3081
3
 楼主| 发表于 2009-6-9 00:13:08 | 显示全部楼层
def move
    if @wait_count > 0
       @wait_count -= 1
      return
    end
    @wait_count = 5 # 按说是跳过这句  可删了这句的话效果就不一样了
   
    if @dir == 1
      if @black.y == 0
        overevents
        return
      end
        @black.y -= 16
    elsif @dir == 2
      if @black.y == 480
        overevents
        return
      end
        @black.y += 16
    elsif @dir == 3
      if @black.x == 0
        overevents
        return
      end
        @black.x -= 16
    elsif @dir == 4
      if @black.x == 640
        overevents
        return
      end
        @black.x += 16
    end

  end

  def overevents
    @black.dispose
    $scene = Scene_Title.new
  end

还有点拌 我自己想会儿
先下了 谢谢大家的回答{/wx}
《隋唐乱》完整解密版点击进入
米兰,让我怎么说离开……

曾经我也是一个有志青年,直到我膝盖中了一箭……

《隋唐乱》博客地址
回复 支持 反对

使用道具 举报

Lv1.梦旅人

蚂蚁卡卡

梦石
0
星屑
116
在线时间
66 小时
注册时间
2007-12-16
帖子
3081
4
 楼主| 发表于 2009-6-9 05:45:04 | 显示全部楼层
def abc
n = 1
if n > 0
   return n
end
n  = 100
end
p abc  #既为1  因为 n > 0 时 return n 退出了abc函数运行并反回了n的值而 n = 100 没有运行,所以 abc 既为 1..

  1. #==============================================================================
  2. # ■ Game_Character (分割定义 2)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 刷新画面
  10.   #--------------------------------------------------------------------------
  11.   def update
  12.     # 跳跃中、移动中、停止中的分支
  13.     if jumping?
  14.       update_jump
  15.     elsif moving?
  16.       update_move
  17.     else
  18.       update_stop
  19.     end
  20.     # 动画计数超过最大值的情况下
  21.     # ※最大值等于基本值减去移动速度 * 1 的值
  22.     if @anime_count > 18 - @move_speed * 2
  23.       # 停止动画为 OFF 并且在停止中的情况下
  24.       if not @step_anime and @stop_count > 0
  25.         # 还原为原来的图形
  26.         @pattern = @original_pattern
  27.       # 停止动画为 ON 并且在移动中的情况下
  28.       else
  29.         # 更新图形
  30.         @pattern = (@pattern + 1) % 4
  31.       end
  32.       # 清除动画计数
  33.       @anime_count = 0
  34.     end
  35.     # 等待中的情况下
  36.     if @wait_count > 0
  37.       # 减少等待计数
  38.       @wait_count -= 1
  39.       return
  40.     end
  41.     # 强制移动路线的场合
  42.     if @move_route_forcing
  43.       # 自定义移动
  44.       move_type_custom
  45.       return
  46.     end
  47.     # 事件执行待机中并且为锁定状态的情况下
  48.     if @starting or lock?
  49.       # 不做规则移动
  50.       return
  51.     end
  52.     # 如果停止计数超过了一定的值(由移动频度算出)
  53.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  54.       # 移动类型分支
  55.       case @move_type
  56.       when 1  # 随机
  57.         move_type_random
  58.       when 2  # 接近
  59.         move_type_toward_player
  60.       when 3  # 自定义
  61.         move_type_custom
  62.       end
  63.     end
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● 更新画面 (跳跃)
  67.   #--------------------------------------------------------------------------
  68.   def update_jump
  69.     # 跳跃计数减 1
  70.     @jump_count -= 1
  71.     # 计算新坐标
  72.     @real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
  73.     @real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 更新画面 (移动)
  77.   #--------------------------------------------------------------------------
  78.   def update_move
  79.     # 移动速度转换为地图坐标系的移动距离
  80.     distance = 2 ** @move_speed
  81.     # 理论坐标在实际坐标下方的情况下
  82.     if @y * 128 > @real_y
  83.       # 向下移动
  84.       @real_y = [@real_y + distance, @y * 128].min
  85.     end
  86.     # 理论坐标在实际坐标左方的情况下
  87.     if @x * 128 < @real_x
  88.       # 向左移动
  89.       @real_x = [@real_x - distance, @x * 128].max
  90.     end
  91.     # 理论坐标在实际坐标右方的情况下
  92.     if @x * 128 > @real_x
  93.       # 向右移动
  94.       @real_x = [@real_x + distance, @x * 128].min
  95.     end
  96.     # 理论坐标在实际坐标上方的情况下
  97.     if @y * 128 < @real_y
  98.       # 向上移动
  99.       @real_y = [@real_y - distance, @y * 128].max
  100.     end
  101.     # 移动时动画为 ON 的情况下
  102.     if @walk_anime
  103.       # 动画计数增加 1.5
  104.       @anime_count += 1.5
  105.     # 移动时动画为 OFF、停止时动画为 ON 的情况下
  106.     elsif @step_anime
  107.       # 动画计数增加 1
  108.       @anime_count += 1
  109.     end
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● 更新画面 (停止)
  113.   #--------------------------------------------------------------------------
  114.   def update_stop
  115.     # 停止时动画为 ON 的情况下
  116.     if @step_anime
  117.       # 动画计数增加 1
  118.       @anime_count += 1
  119.     # 停止时动画为 OFF 并且、现在的图像与原来的不同的情况下
  120.     elsif @pattern != @original_pattern
  121.       # 动画计数增加 1.5
  122.       @anime_count += 1.5
  123.     end
  124.     # 事件执行待机中并且不是锁定状态的情况下
  125.     # ※缩定、处理成立刻停止执行中的事件
  126.     unless @starting or lock?
  127.       # 停止计数增加 1
  128.       @stop_count += 1
  129.     end
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 移动类型 : 随机
  133.   #--------------------------------------------------------------------------
  134.   def move_type_random
  135.     # 随机 0~5 的分支
  136.     case rand(6)
  137.     when 0..3  # 随机
  138.       move_random
  139.     when 4  # 前进一步
  140.       move_forward
  141.     when 5  # 暂时停止
  142.       @stop_count = 0
  143.     end
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 移动类型 : 接近
  147.   #--------------------------------------------------------------------------
  148.   def move_type_toward_player
  149.     # 求得与主角坐标的差
  150.     sx = @x - $game_player.x
  151.     sy = @y - $game_player.y
  152.     # 求得差的绝对值
  153.     abs_sx = sx > 0 ? sx : -sx
  154.     abs_sy = sy > 0 ? sy : -sy
  155.     # 如果纵横共计离开 20 个元件
  156.     if sx + sy >= 20
  157.       # 随机
  158.       move_random
  159.       return
  160.     end
  161.     # 随机 0~5 的分支
  162.     case rand(6)
  163.     when 0..3  # 接近主角
  164.       move_toward_player
  165.     when 4  # 随机
  166.       move_random
  167.     when 5  # 前进一步
  168.       move_forward
  169.     end
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ● 移动类型 : 自定义
  173.   #--------------------------------------------------------------------------
  174.   def move_type_custom
  175.     # 如果不是停止中就中断
  176.     if jumping? or moving?
  177.       return
  178.     end
  179.     # 如果在移动指令列表最后结束还没到达就循环执行
  180.     while @move_route_index < @move_route.list.size
  181.       # 获取移动指令
  182.       command = @move_route.list[@move_route_index]
  183.       # 指令编号 0 号 (列表最后) 的情况下
  184.       if command.code == 0
  185.         # 选项 [反复动作] 为 ON 的情况下
  186.         if @move_route.repeat
  187.           # 还原为移动路线的最初索引
  188.           @move_route_index = 0
  189.         end
  190.         # 选项 [反复动作] 为 OFF 的情况下
  191.         unless @move_route.repeat
  192.           # 强制移动路线的场合
  193.           if @move_route_forcing and not @move_route.repeat
  194.             # 强制解除移动路线
  195.             @move_route_forcing = false
  196.             # 还原为原始的移动路线
  197.             @move_route = @original_move_route
  198.             @move_route_index = @original_move_route_index
  199.             @original_move_route = nil
  200.           end
  201.           # 清除停止计数
  202.           @stop_count = 0
  203.         end
  204.         return
  205.       end
  206.       # 移动系指令 (向下移动~跳跃) 的情况下
  207.       if command.code <= 14
  208.         # 命令编号分支
  209.         case command.code
  210.         when 1  # 向下移动
  211.           move_down
  212.         when 2  # 向左移动
  213.           move_left
  214.         when 3  # 向右移动
  215.           move_right
  216.         when 4  # 向上移动
  217.           move_up
  218.         when 5  # 向左下移动
  219.           move_lower_left
  220.         when 6  # 向右下移动
  221.           move_lower_right
  222.         when 7  # 向左上移动
  223.           move_upper_left
  224.         when 8  # 向右上
  225.           move_upper_right
  226.         when 9  # 随机移动
  227.           move_random
  228.         when 10  # 接近主角
  229.           move_toward_player
  230.         when 11  # 远离主角
  231.           move_away_from_player
  232.         when 12  # 前进一步
  233.           move_forward
  234.         when 13  # 后退一步
  235.           move_backward
  236.         when 14  # 跳跃
  237.           jump(command.parameters[0], command.parameters[1])
  238.         end
  239.         # 选项 [无视无法移动的情况] 为 OFF 、移动失败的情况下
  240.         if not @move_route.skippable and not moving? and not jumping?
  241.           return
  242.         end
  243.         @move_route_index += 1
  244.         return
  245.       end
  246.       # 等待的情况下
  247.       if command.code == 15
  248.         # 设置等待计数
  249.         @wait_count = command.parameters[0] * 2 - 1
  250.         @move_route_index += 1
  251.         return
  252.       end
  253.       # 朝向变更系指令的情况下
  254.       if command.code >= 16 and command.code <= 26
  255.         # 命令编号分支
  256.         case command.code
  257.         when 16  # 面向下
  258.           turn_down
  259.         when 17  # 面向左
  260.           turn_left
  261.         when 18  # 面向右
  262.           turn_right
  263.         when 19  # 面向上
  264.           turn_up
  265.         when 20  # 向右转 90 度
  266.           turn_right_90
  267.         when 21  # 向左转 90 度
  268.           turn_left_90
  269.         when 22  # 旋转 180 度
  270.           turn_180
  271.         when 23  # 从右向左转 90 度
  272.           turn_right_or_left_90
  273.         when 24  # 随机变换方向
  274.           turn_random
  275.         when 25  # 面向主角的方向
  276.           turn_toward_player
  277.         when 26  # 背向主角的方向
  278.           turn_away_from_player
  279.         end
  280.         @move_route_index += 1
  281.         return
  282.       end
  283.       # 其它指令的场合
  284.       if command.code >= 27
  285.         # 命令编号分支
  286.         case command.code
  287.         when 27  # 开关 ON
  288.           $game_switches[command.parameters[0]] = true
  289.           $game_map.need_refresh = true
  290.         when 28  # 开关 OFF
  291.           $game_switches[command.parameters[0]] = false
  292.           $game_map.need_refresh = true
  293.         when 29  # 更改移动速度
  294.           @move_speed = command.parameters[0]
  295.         when 30  # 更改移动频度
  296.           @move_frequency = command.parameters[0]
  297.         when 31  # 移动时动画 ON
  298.           @walk_anime = true
  299.         when 32  # 移动时动画 OFF
  300.           @walk_anime = false
  301.         when 33  # 停止时动画 ON
  302.           @step_anime = true
  303.         when 34  # 停止时动画 OFF
  304.           @step_anime = false
  305.         when 35  # 朝向固定 ON
  306.           @direction_fix = true
  307.         when 36  # 朝向固定 OFF
  308.           @direction_fix = false
  309.         when 37  # 穿透 ON
  310.           @through = true
  311.         when 38  # 穿透 OFF
  312.           @through = false
  313.         when 39  # 在最前面显示 ON
  314.           @always_on_top = true
  315.         when 40  # 在最前面显示 OFF
  316.           @always_on_top = false
  317.         when 41  # 更改图形
  318.           @tile_id = 0
  319.           @character_name = command.parameters[0]
  320.           @character_hue = command.parameters[1]
  321.           if @original_direction != command.parameters[2]
  322.             @direction = command.parameters[2]
  323.             @original_direction = @direction
  324.             @prelock_direction = 0
  325.           end
  326.           if @original_pattern != command.parameters[3]
  327.             @pattern = command.parameters[3]
  328.             @original_pattern = @pattern
  329.           end
  330.         when 42  # 不更改不透明度
  331.           @opacity = command.parameters[0]
  332.         when 43  # 更改合成方式
  333.           @blend_type = command.parameters[0]
  334.         when 44  # 演奏 SE
  335.           $game_system.se_play(command.parameters[0])
  336.         when 45  # 脚本
  337.           result = eval(command.parameters[0])
  338.         end
  339.         @move_route_index += 1
  340.       end
  341.     end
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● 增加步数
  345.   #--------------------------------------------------------------------------
  346.   def increase_steps
  347.     # 清除停止步数
  348.     @stop_count = 0
  349.   end
  350. end
复制代码


默认脚本Game_Character 2

问题:37行 如果当@wait_count > 0时 @wait_count -= 1
然后 下面的
  1. # 强制移动路线的场合
  2.     if @move_route_forcing
  3.       # 自定义移动
  4.       move_type_custom
  5.       return
  6.     end
  7.     # 事件执行待机中并且为锁定状态的情况下
  8.     if @starting or lock?
  9.       # 不做规则移动
  10.       return
  11.     end
复制代码

就都不执行了?


类似 def move
   if @wait_count > 0
      @wait_count -= 1
     return
   end
   @wait_count = 5   
   if @dir == 1
     if @black.y == 0
       overevents
       return
     end
……
如果 @wait_count > 0 的话 @wait_count -= 1
然后下面 @wait_count = 5   if @dir == 1 部分就直接返回不执行了?


《隋唐乱》完整解密版点击进入
米兰,让我怎么说离开……

曾经我也是一个有志青年,直到我膝盖中了一箭……

《隋唐乱》博客地址
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-5 07:35

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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