0
我試圖將我的PC XNA遊戲移植到Xbox上,並試圖在我現有的PC文件管理中實現XNA easystorage以獲得高分。基本上試圖結合http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx與http://easystorage.codeplex.com/XNA XBOX高分端口
我遇到了一個關於LoadHighScores()的特定錯誤,因爲'return(data)'錯誤;' - 使用未分配的局部變量'data'。
我認爲這是由於easystorage/xbox的異步設計!?但不知道如何解決 - 下面是代碼示例:
最初的PC CODE:(適用於PC)
公共靜態HighScoreData LoadHighScores(字符串文件名){ HighScoreData數據; //獲取保存遊戲
string fullpath = "Content/highscores.lst";
// Open the file
FileStream stream = File.Open(fullpath, FileMode.Open,FileAccess.Read);
try
{ // Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{ // Close the file
stream.Close();
}
return (data);
}
XBOX端口的路徑:(有誤差)
公共靜態HighScoreData LoadHighScores(字符串容器,字符串文件名){ HighScoreData數據;
if (Global.SaveDevice.FileExists(container, filename))
{
Global.SaveDevice.Load(container, filename, stream =>
{
File.Open(Global.fileName_options, FileMode.Open,//FileMode.OpenOrCreate,
FileAccess.Read);
try
{
// Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{
// Close the file
stream.Close();
}
});
}
return (data);
}
任何想法?
+1我注意到了Xbox可以是這個地方的桌面CLR是一個很大的寬容很挑剔.. – MattDavey
謝謝,但不作爲數據的工作是一個結構,他們都是非 - 無 - 其他想法? public struct HighScoreData { public string [] Name; public int [] Score; public int [] Level; public int Count; public HighScoreData(int count) { Name = new string [count]; Score = new int [count]; Level = new int [count]; Count = count; } } – user1003211
在這種情況下,您只需要將data = new MyStruct()。編譯器抱怨說有可能在沒有爲數據賦值的情況下達到方法的退出。 – MattDavey