Thread: Very strange error...

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

    Very strange error...

    Well, I started writing this awhile ago, before I knew what a class was (Unfortunantly) So organizing data is... Horrible and slow ;P.

    My error is weird, instead of highlightin what It should be (The set my mouse is over), it highlights my last created set (Explained in a sec). My "sets" are just 2 coords. I'm not sure why, though. I've looked it over and the only reason I can see is that my data organization has screwed the possiblity of this working -,-.

    Heres my problem code:

    Code:
    #define TeleportE '+' //Teleport Enterence
    #define TeleportD '!' //Teleport Destination
    
    #define TriggerE 't'
    #define TriggerP 'p'
    
    HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO inf; 
    CONSOLE_CURSOR_INFO Cur;
    WORD Scolor;
    WORD Scurso;
    char CurPeice;
    int Ticker, MOUSEX, MOUSEY;
    COORD RSP;
    char Ext[1];
    
    //-----------------------------
    BOOL Active_Trigger = 0;    //|
    int  Active_Trigger_Id = 0; //|
                                //|
    BOOL Active_Tele = 0;       //|
    int  Active_Tele_Id = 0;    //|
    //-----------------------------
    
    COORD TE[1000];                //Teleporter Enterence array
    COORD TD[1000];                //Teleporter Destination array
    int NOE = 0;                   //Number of Teleporters
    int NOD = 0;
    
    COORD Trigger[1000];           //Trigger Array
    int NOT = 0;                   //Number of Triggers
    COORD Effect[1000];            //Trigger Effect Array
    int NOTE = 0;                  //Number of Trigger Effects
    COORD OldCharPos[1000];        //Old char positions for effects
    char OldChar[1][1000];         //Old chars for effects
    
    //--------------------------------------------------------Problem code \/
    
    char ReadPos(SHORT x, SHORT y) {
     DWORD reader;
     COORD Pos;
     char EEE[1];
     SHORT v;
    
     Pos.X = x;
     Pos.Y = y;
    
     ReadConsoleOutputCharacter(hOt, &EEE[0], 1, Pos, &reader);
    
     return EEE[0];
    }
    
    int FindTeleporter(BOOL EoE, int x, int y) { //Enterence (0) Exit (1)
     int l = 0;
    
     if(EoE == 0) { //Enterence
    
      for(l = 0; l <= NOE; l++)
       if(x == TE[l].X && y == TE[l].Y)
        return l;
     }
    
     if(EoE == 1) { //Exit
      for(l = 0; l <= NOD; l++)
       if(x == TD[l].X && y == TD[l].Y)
        return l;
     }
    
     return -1;
    }
    
    int FindTrigger(BOOL EoE, int x, int y) { //Enterence (0) Exit (1)
     int l = 0;
    
     if(EoE == 0) { //Enterence
      for(l = 0; l <= NOT; l++)
       if(x == Trigger[l].X && y == Trigger[l].Y)
        return l;
     }
    
     if(EoE == 1) {
      for(l = 0; l <= NOTE; l++)
       if(x == Effect[l].X && y == Effect[l].Y)
        return l;
     }
    
     return -1;
    }
    
    void ColorId(int Id, int Type) {
    
     if(Type == 1) { //Trigger
      SetConsoleCursorPosition(hOt, Trigger[Id]);
      SetColor('r');
      cout << TriggerE;
      SetConsoleCursorPosition(hOt, Effect[Id]);
      cout << TriggerP;
      SetColor('o');
     }
    
     if(Type == 2) { //Teleporter
      SetConsoleCursorPosition(hOt, TE[Id]);
      SetColor('r');
      cout << TeleportE;
      SetConsoleCursorPosition(hOt, TD[Id]);
      cout << TeleportD;
      SetColor('o');
     }
    }
    
    void ResetId(int Id, int Type) {
    
     if(Type == 1) { //Trigger
      SetConsoleCursorPosition(hOt, Trigger[Id]);
      SetColor('o');
      cout << TriggerE;
      SetConsoleCursorPosition(hOt, Effect[Id]);
      cout << TriggerP;
     }
    
     if(Type == 2) { //Teleporter
      SetConsoleCursorPosition(hOt, TE[Id]);
      SetColor('o');
      cout << TeleportE;
      SetConsoleCursorPosition(hOt, TD[Id]);
      cout << TeleportD;
     }
    }
    
    int ActivateNode(SHORT x, SHORT y) {
     int z;
     char c;
    
     if(Active_Tele_Id > 0)
      ResetId(Active_Tele_Id, 2);
     Active_Tele = 0;
     Active_Tele_Id = 0;
    
     if(Active_Trigger_Id > 0)
      ResetId(Active_Trigger_Id, 1);
     Active_Trigger = 0;
     Active_Trigger_Id = 0;
    
     c = ReadPos(x, y);
    
     if(c == Blank)
      return 0;
    
     if(c == TriggerE) {
      Active_Trigger = 1;
      Active_Trigger_Id = FindTrigger(0, x, y);
      if(Active_Trigger_Id == -1)
       return 0;
      ColorId(Active_Trigger_Id, 1);
      return 1;
     }
    
     if(c == TriggerP) {
      Active_Trigger = 1;
      Active_Trigger_Id = FindTrigger(1, x, y);
      if(Active_Trigger_Id == -1)
       return 0;
      ColorId(Active_Trigger_Id, 1);
      return 1;
     }
    
     if(c == TeleportE) {
      Active_Tele = 1;
      Active_Tele_Id = FindTeleporter(0, x, y);
      if(Active_Tele_Id == -1)
       return 0;
      ColorId(Active_Tele_Id, 2);
      return 1;
     }
    
     if(c == TeleportD) {
      Active_Tele = 1;
      Active_Tele_Id = FindTeleporter(1, x, y);
      if(Active_Tele_Id == -1)
       return 0;
      ColorId(Active_Tele_Id, 2);
      return 1;
     }
    }
    As you can see, this is very bad data organization, but it would take to long to convert this, c-type no class style is pritty inset in this particular program. I dont see any reason that this would select only my last set. Not only that, once it does it wont deselect or reselect until I make a new set, and if I hit select pair after I make a new set, it selects the newest set. I dont see why... Does anyone?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Haven't read the code - just compiled
    Here are my warnings, maybe one of them will give a hint
    Code:
    Ignoring return value of function 'ReadConsoleOutputCharacterA(void *, char *, unsigned long, struct _COORD, unsigned long *)'
    Ignoring return value of function 'SetConsoleCursorPosition(void *, struct _COORD)'
    function 'ActivateNode(short, short)' should return a value (see line 141))
    Symbol 'z' (line 142) not subsequently referenced)
    Symbol 'ActivateNode(short, short)' (line 141, file ) not referenced)
    Symbol 'Active_Tele' (line 28, file ) not accessed)
    Symbol 'Active_Trigger' (line 25, file ) not accessed)
    Symbol 'Ext' (line 22, file ) not referenced)
    'Scolor' (line 17, file ) not referenced)
    'OldCharPos' (line 41, file ) not referenced)
    'OldChar' (line 42, file ) not referenced)
    'MOUSEX' (line 20, file ) not referenced)
    'MOUSEY' (line 20, file ) not referenced)
    'RSP' (line 21, file ) not referenced)
    'Effect' (line 39, file ) not explicitly initialized)
    'Trigger' (line 37, file ) not explicitly initialized)
    'TD' (line 33, file ) not explicitly initialized)
    'TE' (line 32, file ) not explicitly initialized)
    'Cur' (line 16, file ) not referenced)
    Symbol 'CurPeice' (line 19, file ) not referenced)
    Symbol 'Ticker' (line 20, file ) not referenced)
    Symbol 'Scurso' (line 18, file ) not referenced)
    Symbol 'inf' (line 15, file ) not referenced)
    Symbol 'hIn' (line 14, file ) not referenced)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    I'm suprised it compiled. There is no main in that peice of code, additionaly its just the header of a .cpp file which has one or two other constants.

    I dont think any of thoes warnings are related to this though, it seems like a value I set somewhere is throwing this off. Or prehaps I'm sorting inaccurately. Though I dont see one anywhere. Ah well, a lesson that I should always organize my data before hand -,-.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM