XNA XBOX 高分端口

发布于 2024-12-10 21:55:50 字数 2379 浏览 2 评论 0原文

我正在尝试将我的电脑 XNA 游戏移植到 xbox,并尝试在我现有的电脑文件管理旁边实施 xna easystorage 以获取高分。基本上尝试结合 http://xnaessentials.com/tutorials/highscores.aspx/tutorials /highscores.aspxhttp://easystorage.codeplex.com/

我遇到了一个关于 LoadHighScores() 的特定错误,即“return (data);”错误- 使用未分配的局部变量“data”。

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

原始 PC 代码:(适用于 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 PORT: (有错误)

public static HighScoreData LoadHighScores(string container, string filename) { 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);
    }

有什么想法吗?

I'm trying to port my pc XNA game to the xbox and have tried to implement xna easystorage alongside my existing pc file management for highscores. Basically trying to combine http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx with http://easystorage.codeplex.com/

I'm running into one specific error regarding the LoadHighScores() as error with 'return (data);' - Use of unassigned local variable 'data'.

I presume this is due to async design of easystorage/xbox!? but not sure how to resolve - below are code samples:

ORIGINAL PC CODE: (works on PC)

public static HighScoreData LoadHighScores(string filename)
{
HighScoreData data; // Get the path of the save game

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: (with error)

public static HighScoreData LoadHighScores(string container, string filename)
{
HighScoreData data;

        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);
    }

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-12-17 21:55:50

返回前分配数据。 ;)

  data = (if_struct) ? new your_struct() : null;
  if (Global.SaveDevice.FileExists(container, filename))
  {
     ......
  }
  return (data);
}

Assign data before return. ;)

  data = (if_struct) ? new your_struct() : null;
  if (Global.SaveDevice.FileExists(container, filename))
  {
     ......
  }
  return (data);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文