2016-11-18 57 views
0

下面的脚本是我开始研究的,它需要一个TextAsset并分割线条并将其与各种字符串进行比较。但是我的检查函数只返回false。有什么重大的我想念,统一不会抛出任何错误,所以我不知道该怎么做来解决这个问题。bool isItem(TextAsset f)总是返回false

internal sealed class Checker { 
     private string AssetType(TextAsset fileToBeChecked) { 
      string[] line = fileToBeChecked.text.Split (new char[] { '\n' }); 
      return line [0]; 
     } 
     public bool isItem(TextAsset file) { 
      string type = AssetType (file).ToLower(); 
      if (type == "helmet" || type == "cuirass" || type == "gauntlets" || type == "gloves" || type == "boots" || type == "leggings" || type == "shield" || type == "robes" || type == "shirt" || type == "pants" || type == "shoes" || type == "hood" || type == "staff" || type == "stave" || type == "sword" || type == "greatsword" || type == "dagger" || type == "mace" || type == "warhammer" || type == "axe" || type == "waraxe" || type == "bow" || type == "misc") { 
       return true; 
      } else {    
       return false; 
      } 
     } 
    } 
} 

我的测试文件如下:

Helmet 
1 
Dragon's Vale 
0 
10 
0 
14 
1280 

调试

Debug Image

+0

那么,什么是'type'当您调试呢? –

+0

这应该很容易使用调试器解决。我们不知道'AssetType(file).ToLower()'返回的是什么,因为我们不知道你的上下文。那么我们应该怎么知道为什么这些条件永远不会通过? – HimBromBeere

+0

@EvanTrimboli包含信息状态头盔的文件,当我有功能给我的价值后拉它说头盔。但是当它与“头盔”相比时,它返回了错误。 –

回答

0

事实证明后,我不知道为什么,但加入TRIM()来我的ToLower()解决了这个问题,但我没有看到它,因为同一个文件中的另一个错误阻止了我正确比较这些值。我已经解决了这两个问题,但我不知道为什么Trim在我的类型字符串之前或之后没有任何值时解决了我的问题。无论如何,剧本都按预期工作。

固定的代码是:

private string AssetType(TextAsset fileToBeChecked) { 
    string[] line = fileToBeChecked.text.Split (new char[] { '\n' }); 
    return line [0].Trim(); 
} 
+0

如果添加更改后的行,以便其他人可以更快地找到答案,那将很棒,即显示固定代码位 – TheLethalCoder