我正在尝试将我的PC XNA游戏移植到xbox,并尝试将xna easystorage与我现有的pc文件管理一起用于高分。基本上是尝试将http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx与http://easystorage.codeplex.com/
结合起来我遇到一个关于LoadHighScores()的特定错误,错误为'return(data);' - 使用未分配的局部变量'data'。
我认为这是由于easystorage / xbox的异步设计造成的!?但不知道如何解决 - 以下是代码示例:
原始PC代码:(适用于PC)
public static HighScoreData LoadHighScores(string filename) { 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 PORT :(有错误)
public static 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);
}
有什么想法吗?
答案 0 :(得分:2)
返回前分配数据。 ;)
data = (if_struct) ? new your_struct() : null;
if (Global.SaveDevice.FileExists(container, filename))
{
......
}
return (data);
}