[Help Request] Saving a Custom System (5165)

03/07/2010 20:19 -NewDawn-#1
Hey you guys, I need help. =\
[Only registered and activated users can see links. Click Here To Register...]
I know that sounds lame but it's really hard for me and I've been trying for days.
My goal is to save a variable M and D to a character file in a folder called "example" (Like the Flower System's save system).

[Only registered and activated users can see links. Click Here To Register...]

This is what I have for the System's cs (located in Features called Example.cs):
Code:
[COLOR="Blue"]using[/COLOR] System;
[COLOR="Blue"]using[/COLOR] System.Collections.Generic;
[COLOR="Blue"]using[/COLOR] System.Text;

[COLOR="Blue"]namespace[/COLOR] NewestCOServer
{
    [COLOR="Blue"]public partial class[/COLOR] [COLOR="Teal"]Struct[/COLOR]
    {
        [COLOR="Blue"]public class[/COLOR] [COLOR="Teal"]Example[/COLOR]
        {
            [COLOR="Blue"]public int[/COLOR] D;
            [COLOR="Blue"]public int[/COLOR] M;
            [COLOR="Blue"]public int[/COLOR] CanGetX;
        
        }
    }
}
CanGetX is referring to being able to obtain an item.

Then, I have this is the database:
Code:
[COLOR="Blue"]public static void[/COLOR] LoadExample([COLOR="Blue"]string[/COLOR] name)
        {
            [COLOR="Blue"]if [/COLOR]([COLOR="Teal"]File[/COLOR].Exists([COLOR="DarkRed"]@"C:\OldCODB\Example\"[/COLOR] + name + [COLOR="DarkRed"]".chr"[/COLOR]))
            {
                [COLOR="Teal"]FileStream[/COLOR] fs = [COLOR="Blue"]new[/COLOR] [COLOR="Teal"]FileStream[/COLOR]([COLOR="DarkRed"]@"C:\OldCODB\Example\"[/COLOR] + name + [COLOR="DarkRed"]".chr"[/COLOR], [COLOR="Teal"]FileMode[/COLOR].Open);
                [COLOR="Teal"]BinaryReader[/COLOR] br = [COLOR="Blue"]new[/COLOR] [COLOR="Teal"]BinaryReader[/COLOR](fs);

                [COLOR="Blue"]try[/COLOR]
                {
                    Game.[COLOR="Teal"]Character[/COLOR] CC = [COLOR="Teal"]World[/COLOR].CharacterFromName(name);

                    CC.Example.M = br.ReadInt32();
                    CC.Example.D = br.ReadInt32();
                    CC.Example.CanGetX = br.ReadInt32();
                    

                    fs.Flush();

                    br.Close();
                    fs.Close();
                }
                [COLOR="Blue"]catch[/COLOR] ([COLOR="Teal"]Exception[/COLOR] e) { [COLOR="Teal"]Console[/COLOR].WriteLine(e); }
            }
        }
        [COLOR="Blue"]public static void[/COLOR] SaveExample([COLOR="Blue"]string[/COLOR] name)
        {
            [COLOR="Blue"]if [/COLOR]([COLOR="Teal"]File[/COLOR].Exists([COLOR="DarkRed"]@"C:\OldCODB\Example\"[/COLOR] + name + [COLOR="DarkRed"]".chr"[/COLOR]))
            {
                [COLOR="Teal"]FileStream[/COLOR] fs = [COLOR="Blue"]new[/COLOR] [COLOR="Teal"]FileStream[/COLOR]([COLOR="DarkRed"]@"C:\OldCODB\Example\"[/COLOR] + name + [COLOR="DarkRed"]".chr"[/COLOR], [COLOR="Teal"]FileMode[/COLOR].Open);
                [COLOR="Teal"]BinaryReader[/COLOR] br = [COLOR="Blue"]new[/COLOR] [COLOR="Teal"]BinaryReader[/COLOR](fs);

                [COLOR="Blue"]try[/COLOR]
                {
                    Game.[COLOR="Teal"]Character[/COLOR] CC = [COLOR="Teal"]World[/COLOR].CharacterFromName(name);
                    bw.Write(CC.Example.M);
                    bw.Write(CC.Example.D);
                    bw.Write(CC.Example.CanGetX);
                    

                    bw.Flush();
                    fs.Flush();
                    bw.Close();
                    fs.Close();
                }
                [COLOR="Blue"]catch[/COLOR] ([COLOR="Teal"]Exception[/COLOR] e) { [COLOR="Teal"]Console[/COLOR].WriteLine(e); }

            }
        }
Then I have it so that the player can go up to an NPC and set D and M.
When the character types something in as D or M, it sets it temporarily as:
GC.MyChar.Example.D = (number);

The problem is, I don't know how it will save it. :(
Please help =\
[Only registered and activated users can see links. Click Here To Register...]
03/07/2010 20:25 hunterman01#2
Well this isnt really a big deal but

Console.Writeline(e.ToString());

At least thats how i do it
03/07/2010 20:26 xScott#3
im confused, you want to write Two variables to a file, And then read the line and get the two words from the line ?
03/07/2010 20:28 -NewDawn-#4
Quote:
Originally Posted by hunterman01 View Post
Well this isnt really a big deal but

Console.Writeline(e.ToString());

At least thats how i do it
What does that do? I mean, how would i implement that into the NPC?

Quote:
Originally Posted by xScott View Post
im confused, you want to write Two variables to a file, And then read the line and get the two words from the line ?
I want it to save 2 numbers, one to M and one to D from the NPC.
03/07/2010 20:39 hunterman01#5
Quote:
Originally Posted by -NewDawn- View Post
What does that do? I mean, how would i implement that into the NPC?



I want it to save 2 numbers, one to M and one to D from the NPC.
Your pretty much doing the same thing it's just i like my way better :)
03/07/2010 21:37 Korvacs#6
What youve written for the save method is correct, whats your problem?
03/07/2010 23:09 -NewDawn-#7
Quote:
Originally Posted by Korvacs View Post
What youve written for the save method is correct, whats your problem?
I don't know how to access it. I want it so if you say M = 13 using an NPC in Twin City, i want it to save... but when It sets GC.MyChar.Example.M = 13; it goes away after a d/c or log off. It doesn't save to the Example folder in OldCODB.
03/07/2010 23:16 -Shunsui-#8
Quote:
Originally Posted by -NewDawn- View Post
I don't know how to access it. I want it so if you say M = 13 using an NPC in Twin City, i want it to save... but when It sets GC.MyChar.Example.M = 13; it goes away after a d/c or log off. It doesn't save to the Example folder in OldCODB.
Make it save, in the character look at the ExpBallUsed per day bool or w,e it is, save it how that is been saved or the lottery used per day
03/07/2010 23:24 -NewDawn-#9
Quote:
Originally Posted by -Shunsui- View Post
Make it save, in the character look at the ExpBallUsed per day bool or w,e it is, save it how that is been saved or the lottery used per day
So...
BW.Write(C.ExpBallsUsedToday);

So... I'd say something like:
BW.Write(C.Example.M);
in NPCDialog...

C being defined as:
Game.Character C = new NewestCOServer.Game.Character();

Is that right?

EDIT: Still doesn't work... nothing is in the Example Folder...
03/08/2010 03:02 walmartboi#10
You don't have a method to even create the file "example.chr" or whatever this is, and this is straight from my flowers save =o
03/08/2010 03:12 herekorvac#11
whats with the e.tostring?
why not e.message?