Thread: Loading paired coords... Yeesh >.>.

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Loading paired coords... Yeesh >.>.

    *Fixed *

    Well, I got my save code working... But loading... not yet... When it should place the characters in there former positions, it doesnt place them... Anywhere? I know it it loads the file proprely, and I'm fairly sure it parses correctly. But, I dont think the coord variables are getting the correct information... Heres load code:
    (Borland BCC55 compiler, Windows XP)
    Code:
    void Load() {
     string MAP;
     string PATH;
     char Saveme[2];
     int x00;
     COORD wha;
     string s;
     string s2;
     string ko;
     stringstream ss;
     int i, a;
     BOOL sswitch = false;
    
     PATH="C:\\";
     PATH+=Ext[0];
     PATH+=".bsf";
    
     ifstream file_in2(PATH.c_str(), ios::nocreate);
    
     s="";
    
     for(;;) {
      file_in2.get(Saveme[1]);
      if(Saveme[1] == 'a')
       break;
      if(Saveme[1] == ';')
       sswitch = true;
      if(Saveme[1] == ';' || Saveme[1] == 'n' ||Saveme[1] == 'e' ||Saveme[1] == '\n')
       cout << "";
      else {
       if(sswitch == false)
        s+=Saveme[1];
       else
        s2+=Saveme[1];
      }
     }
    
     a = 0;
     ko = "";
    
     for(i=0; a < s.length(); i++) {
      ss.clear();
      ko[0] = s[a];
      ko[1] = s[++a];
      ss << ko;
      ss >> TE[i].X;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> TE[i].Y;
    
      NOE = a + 1;
      NOD = a + 1;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> TD[i].X;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> TD[i].Y;
    
      a++;
     }
    
     a = 0;
     ko = "";
    
     for(i=0; a < s.length(); i++) {
      ss.clear();
      ko[0] = s[a];
      ko[1] = s[++a];
      ss << ko;
      ss >> Trigger[i].X;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> Trigger[i].Y;
    
      NOT = a + 1;
      NOTE = a + 1;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> Effect[i].X;
    
      ss.clear();
      ko[0] = s[++a];
      ko[1] = s[++a];
      ss << ko;
      ss >> Effect[i].Y;
    
      a++;
     }
    
     for(a=0; a <= NOE; a++) {
      wha.X = TE[a].X;
      wha.Y = TE[a].Y;
      SetConsoleCursorPosition(hOt, wha);
      cout << TeleportE;
     }
     for(a=0; a <= NOD; a++) {
      wha.X = TD[a].X;
      wha.Y = TD[a].Y;
      SetConsoleCursorPosition(hOt, wha);
      cout << TeleportD;
     } 
     for(a=0; a <= NOT; a++) {
      wha.X = Trigger[a].X;
      wha.Y = Trigger[a].Y;
      SetConsoleCursorPosition(hOt, wha);
      cout << TriggerE;
     }
     for(a=0; a <= NOTE; a++) {
      wha.X = Effect[a].X;
      wha.Y = Effect[a].Y;
      SetConsoleCursorPosition(hOt, wha);
      cout << TriggerP;
     }
    
     file_in2.close();
    }
    (TE, TD, Trigger, Effect, NOE, NOD, NOT, NOTE are all globals. TriggerE, TriggerP, TeleportE, TeleportD are all pre-defined constants.)

    To the extent of my knowledge, this should work. The file has coord pairs like:4516n4615e

    Heres the file that should be loading:
    (1.BSF)
    Code:
    4516n4816e
    4716n4916e
    
    ;
    
    a
    When the files opened, the information before the ; should be sent to TE and TD. The n & e split lines. IE TE[0].Xshould be 45, and TE[0].Yshould be 16. Then TD[0].X should be 48, and TD[0].Y should be 16... There are no integers for Trigger / Effect placed currently.

    It doesnt work however, I know the code does alot it.. doesnt particularly need to do, but in essence it should work... I dont see any reason it doesnt? Take two chars, put them in a string and send them to the a global coord. I've re-designed this code fifty times, but nothing seems to work. The closest I got was it place the characters directly mirrored to where they should be. (Say it was at 0, 0 it would go to the very edge of the command prompts screen... (Dont ask how I managed that ... ) I know there are lots of variables defined there that arent used... I cut out the code that wasnt related to loading / parsing the bsf file.

    Thanks for your time! >.>
    Last edited by Blackroot; 08-19-2006 at 02:31 AM.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > file_in2.get(Saveme[1]);
    If you're just reading one char, why make Saveme an array. Why not just:
    Code:
    char Saveme;
    > ss.clear();
    I'm almost positive this doesn't clear the stream. If just clears the error flags. I believe you want:
    Code:
    ss.str("");
    > ko[0] = s[a];
    > ko[1] = s[++a];
    Simpler is:
    Code:
    ko = s.substr(a,2);
    a += 2;

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Well... It loads... Much more accurate, but no cigar. I'm not sure whats wrong, but it seems to be an issue with saving. Thank you very much for your help swoopy .
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    ios::nocreate is deprecated.

    Code:
    while(getline(file, string_line))
    {
           stringstream s;
    
           if(string_line.length() == 10 && string_line != ";") // give it a go
    
           // convert all these bad boys outta the stringstream
           // use return of extraction operator >> for sanity checks
    
           s.str(string_line.substr(0, 2)); // x
           s.str(string_line.substr(2,2));  // y
           s.str(string_line.substr(4, 1)); // n, sanity check
    
           s.str(string_line.substr(5, 2)); // x
           s.str(string_line.substr(7, 2)); // y
           s.str(string_line.substr(9, 1)); // e, sanity check
    }
    Simplify things! So much complexity seems uneeded, but I didn't even look so I dunno!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cargo loading system
    By kyle rull in forum C Programming
    Replies: 1
    Last Post: 04-20-2009, 12:16 PM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Loading Screen
    By pinkcheese in forum Windows Programming
    Replies: 2
    Last Post: 04-06-2002, 11:48 PM