XNA XBOX highscore端口

XNA XBOX highscore端口,xna,xbox,Xna,Xbox,我正在尝试将我的pc XNA游戏移植到xbox,并尝试在现有pc文件管理的基础上实现XNA easystorage以获得高分。基本上是试图与 我遇到了一个特定的错误,将LoadHighScores()视为带有“return(data);”的错误使用未分配的局部变量“数据” 我认为这是由于easystorage/xbox!的异步设计造成的!?但不确定如何解决-以下是代码示例: 原始PC代码:(在PC上工作) 公共静态HighScore数据加载HighScores(字符串文件名) { HighSco

我正在尝试将我的pc XNA游戏移植到xbox,并尝试在现有pc文件管理的基础上实现XNA easystorage以获得高分。基本上是试图与

我遇到了一个特定的错误,将LoadHighScores()视为带有“return(data);”的错误使用未分配的局部变量“数据”

我认为这是由于easystorage/xbox!的异步设计造成的!?但不确定如何解决-以下是代码示例:

原始PC代码:(在PC上工作)

公共静态HighScore数据加载HighScores(字符串文件名) { 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(字符串容器、字符串文件名) { 高分数据

        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要宽容得多。谢谢,但这不起作用,因为数据是一个结构,它们不可为空-还有其他想法吗?public struct HighScoreData{public string[]Name;public int[]Score;public int[]ScoreLevel;public int Count;public HighScoreData(int Count){Name=new string[Count];Score=new int[Count];Level=new int[Count];Count=Count;}在这种情况下,只需将data=newmystruct()放入.编译器抱怨说,不给数据赋值就可以到达方法的出口..谢谢-我想我必须重新考虑整个方法,或者中断,直到我的大脑清醒!就像在我原始帖子的第一个链接中概述的PC版本一样-我“初始化”前十名分数和创建文件,以及何时在选择savedevice后,通过实现createscores()移植尝试将其移动如果不存在任何文件,但global.savedevice仍未定义且未创建任何文件,即使我收到选择内存选项的提示。在xbox上保存数据比在PC上保存数据要复杂得多!这必须是将一组数字保存到文件的更简单的方法:)
  data = (if_struct) ? new your_struct() : null;
  if (Global.SaveDevice.FileExists(container, filename))
  {
     ......
  }
  return (data);
}