保存文件系统我尝试开发不起作用。 [英] Save file system I tried developing isn't working.

查看:56
本文介绍了保存文件系统我尝试开发不起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上只是一个简单的系统,应该允许我正在制作的游戏来保存各种参数。涉及的两个方法(Read(int)和Save(int,int))导致没有错误或异常,但无论我如何使用它们,保存文件本身(具有
格式的"0000 0000 ") ; 0000  0000 ..."保持不变。

This is really just a simple system that should allow a game I'm making to save various parameters. The two methods involved (Read(int) and Save(int,int)) result in no errors or exceptions, but no matter how I use them, the save file itself (which has a format of "0000 0000 0000 0000...") remains the same.

请注意,Read(int)方法工作正常,它是Save(int,int)方法,这就是问题。

And note that the Read(int) method works perfectly, it's the Save(int,int) method which is the problem.

以下是两种方法的代码:

Here's the code for both methods:

public void Save(int SName,int SSave )

        {

            if(!File.Exists((@"c:\ Epicade \ Savave \ Yeah.txt"))))
            {

                int MarkerInSave = 0;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int SfSize = 0; SfSize< 1000; SfSize ++)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MarkerInSave ++;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; File.AppendAllText(@" c:\ Epicade \Save \Yeah.txt"," 0000");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int TSName = SName * 5;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string SSect = File.ReadAllText(@" c:\ Game \Save\Yeah.txt");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string FSect = SSect.Substring(TSName + 1);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string BSect ="" ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(SSave> = 9){BSect =" 000" + Convert.ToString(SSave); }其他

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(SSave> = 99){BSect =" 00" + Convert.ToString(SSave); }其他

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(SSave> = 999){BSect =" 0" + Convert.ToString(SSave); }其他

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(SSave> = 9999){BSect = Convert.ToString(SSave); } else {}

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SSect.Insert(TSName,BSect);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SSect.Remove(TSName + 1);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SSect.Insert(TSName + 1,FSect);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; File.WriteAllText(@" c:\ Game \Save \Yeah.txt",SSect);

public void Save(int SName, int SSave)
        {
            if (!File.Exists((@"c:\Epicade\Save\Yeah.txt")))
            {
                int MarkerInSave = 0;
                for (int SfSize = 0; SfSize < 1000; SfSize++)
                {
                    MarkerInSave++;
                    File.AppendAllText(@"c:\Epicade\Save\Yeah.txt", "0000 ");
                }
            }
            int TSName = SName * 5;
            string SSect = File.ReadAllText(@"c:\Game\Save\Yeah.txt");
            string FSect = SSect.Substring(TSName + 1);
            string BSect = "";
            if (SSave >= 9) { BSect = "000" + Convert.ToString(SSave); } else
            if (SSave >= 99) { BSect = "00" + Convert.ToString(SSave); } else
            if (SSave >= 999) { BSect = "0" + Convert.ToString(SSave); } else
            if (SSave >= 9999) { BSect = Convert.ToString(SSave); } else { }
            SSect.Insert(TSName, BSect);
            SSect.Remove(TSName + 1);
            SSect.Insert(TSName + 1, FSect);
            File.WriteAllText(@"c:\Game\Save\Yeah.txt", SSect);

}

推荐答案

不确定您要实现的目标,但首先要创建一个填充的文件'0'在  c:\ Epicade \Save\Yeah.txt,但随后读取
返回不同的文件 
c:\ Game \Save\Yeah.txt。它是否正确? (因为你说没有例外,我猜c:\ Game \Save\Yeah.txt
必须存在/

你然后有:

SSect.Insert(TSName, BSect);
SSect.Remove(TSName + 1);
SSect.Insert(TSName + 1, FSect);

插入和删除函数实际上返回插入或删除子字符串的新字符串(它们不会更改原始字符串)。

The Insert and Remove functions actually return new strings with the substring inserted or removed (they do not change the original string).

你没有对返回值做任何事情。所以我猜你想说:

You are not doing anything with the return values. So I'm guessing you meant to say:

SSect = SSect.Insert(TSName, BSect);
SSect = SSect.Remove(TSName + 1);
SSect = SSect.Insert(TSName + 1, FSect);




但即使你这样做,我想你会在一个位置插入价值BSect,然后从位置+ 1中删除所有内容(包括除了刚刚插入的值的第一个字符之外的所有内容),然后插入FSect,这是你的子字符串早先提取了
。你的意图是什么?

But even if you did this, I think you would be inserting the value BSect at a position, then removing everything from position + 1 (including all but the first char of the value you just inserted) then inserting FSect which is the substring you extracted earlier. What is your intention here?

调试器是你的朋友。


这篇关于保存文件系统我尝试开发不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆