problem with selection code

This is a discussion on problem with selection code within the Game Programming forums, part of the General Programming Boards category; I am having a small problem with my selection code. I had it working awhile back ago so that you ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    problem with selection code

    I am having a small problem with my selection code.

    I had it working awhile back ago so that you could select single units, but you could not select multiple units.

    After working on several other features, I decided to come back to my selection code and implement a method would select multiple units instead of just a single unit.

    Unfortunately, there is a small problem. I use a selection box, obviosly, to designate which units on the screen I want to select. Unfortunately, no matter where I draw my selection box, ALL units get selected no matter what. This is not good. I also have no clue what is going wrong in my code.

    Here is the selection method:
    Code:
    void Select ( int x1, int y1, int x2, int y2, int playerID ) 
        {
            if ( x1 > x2 )
                swap(x1, x2);
            if ( y1 > y2 )
                swap(y1, y2);
        
            if ( playerID == Flag.ALLEGIANCE )
            {
                if ( (WorldX > x1) && (WorldX < x2) &&
                     (WorldY > y1) && (WorldY < y2) )
                {
                    Flag.SELECTED = true;
                }          
    	    else 
    	    {
    		Flag.SELECTED = false;				
    	    }
            }
        }
    It is such a simple method. It baffles me why it does not work.
    My Website

    "Circular logic is good because it is."

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    nevermind!

    found my error...

    stupid me....how stupid could i be?

    that function was virtual function and i overrided it in a derived class with one simple line:

    Flag.SELECTED = true;


    That kind of stuff is sure to screw me up.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with compiling code with option -O2
    By koushikyou in forum C Programming
    Replies: 16
    Last Post: 01-07-2009, 05:03 AM
  2. Selection Sort Problem?
    By dcwang3 in forum C Programming
    Replies: 31
    Last Post: 11-07-2008, 12:25 PM
  3. Problem with progress code
    By JFonseka in forum C Programming
    Replies: 13
    Last Post: 04-25-2008, 05:03 PM
  4. Bubble Sort / selection problem
    By Drew in forum C++ Programming
    Replies: 7
    Last Post: 08-26-2003, 03:23 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21