本帖最后由 喵呜喵5 于 2013-9-28 15:58 编辑
稍微搜索了一下没有找到,于是就自己写了一个……- def position(actor_id)
- #获取输入的角色ID在数据库中对应的数据
- actor = $game_actors[actor_id]
- #判断该数据对应的角色是否在队伍中
- if !$game_party.members.include?(actor)
- #如果不在队伍中,返回0
- return 0
- else
- #如果在队伍中,返回该角色所在的位置
- return $game_party.members.index(actor)+1
- end
- end
复制代码 ============================================================================
更加优雅(蛋疼)的版本……因为如果找不到的话index会返回nil所以代码可以写的更简单一些
def position(actor_id) actor = $game_actors[actor_id] actor = $game_party.members.index(actor) return actor+1 if actor 0 end
def position(actor_id)
actor = $game_actors[actor_id]
actor = $game_party.members.index(actor)
return actor+1 if actor
0
end
|