Problem with sorting an array

This is a discussion on Problem with sorting an array within the Game Programming forums, part of the General Programming Boards category; I'm creating a rpg and I'm having problems with an array sort. the following code is suppossed to sort through ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    139

    Problem with sorting an array

    I'm creating a rpg and I'm having problems with an array sort. the following code is suppossed to sort through a list of skills and if the character already has the skill or if his stats don't allow him to take that skill then it won't be added to the list... but it doesn't seem to be working right. So if someone could help it would be nice.

    Code:
      int start,end,put=0;
      int x;
      Find_skill_type(type,skill_list,start,end);
      for (x=start;x<=end;x++)
      {
        if ((skills[x]==0)&&(stats_allow_skill(stats,skill_list[x])==true))
        {
          menu_list[put]=x;
          put++;
        }
      }
    Find_skill_type() finds the start and end position of skills of a certain type from the main skill list.

    stats_allow_skill() passes back true if he can take it or false if he can't

    skills is the characters skill list (which corresponds to the same point in the skill_list array.)
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You are passing the start and end variables by value, which means the values they get in the function won't be accessible in the for-loop. Use pointers:
    Code:
    Find_skill_type(type, skill_list, &start, &end);
    
    void Find_skill_type(int type, int skill_list, int* start, int* end)
    {
       ...
    
       *start=whatever;
       *end=whatever;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Unregistered
    Guest
    I just figured out the problem twas something in the function that was calling this one. forgot a -1 *sigh*
    oh and and Find_skill_type() uses passing by reference for start and end so that was okay but thanks for replying though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. Problem sorting an array of strings
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 05-07-2008, 10:02 PM
  3. Problem with copying a string into array in a struct
    By JFonseka in forum C Programming
    Replies: 15
    Last Post: 05-04-2008, 06:07 AM
  4. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 05:19 AM
  5. 3D array problem
    By rainman39393 in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2008, 07:09 PM

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