2016-11-18 55 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