Project1

标题: 诡异的循环问题 [打印本页]

作者: zh99998    时间: 2009-2-15 19:13
标题: 诡异的循环问题
Path = ["", "d:\\rpg\\RPG Maker XP\\RGSS\\Standard/"]
ext = ["png", "jpg", ""]
filename = "Graphics/tilesets/001-grassland01"
    Path.each do |path|
      ext.each do |ext|
        filename.insert(0, path)
        filename += "." + ext unless ext.empty?
        p filename,FileTest.exist?(filename)
        return filename if FileTest.exist?(filename)
      end
    end

只p三次,并且第二行都是false,正常应该是p出4次,第四个是true才对 [LINE]1,#dddddd[/LINE]版务信息:本贴由楼主自主结贴~
作者: zh99998    时间: 2009-2-15 19:41
自己解决了- -
变量名的冲突
作者: chenyin    时间: 2009-2-15 20:01
Path = ["D:/o/"]
ext = [".png", ".jpg", ""]
filename = "1"
for l in Path
  for i in ext
    if FileTest.exist?("#{l}#{filename}#{i}")
    p ("#{l}#{filename}#{i}")
    end
  end
end [LINE]1,#dddddd[/LINE]系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~




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