how to increase id number per create?
#9

My suggestion would be create a function which returns the next unused ID. In this case you need to add a new boolean in your enum.
pawn Код:
bool: dUsed
This is the function which would return the next unused ID. You will need no global arrays which store the ID anymore using this method. This method is also a better way for this situation, since you MIGHT make a mistake somewhere in your script with these
pawn Код:
idx--;
or
pawn Код:
idx++;
So basically heres the function:
pawn Код:
GetUnusedDoorID()
{
     for (new i = 0; i < MAX_DOOR; i++) {
          if (DoorInfo[i][dUsed]) continue;
          return i;
     }
     return MAX_DOOR;
}
And make sure when you create a new door:
pawn Код:
DoorInfo[id][dUsed] = true;
And do the opposite when removing the door.

Hope this helps.

EDIT: Theres also one improvement for making it more "automatic". Instead of creating a new boolean in the enum and switching its value to true/false and checking it to return the next ID, you simply can check the doors position. If the X, Y, Z are equal to 0.0 then its probably not created which means the ID is unused. Heres an example:
pawn Код:
GetUnusedDoorID()
{
     for (new i = 0; i < MAX_DOOR; i++) {
          if (DoorInfo[i][dX] == 0.0 && DoorInfo[i][dY] == 0.0 && DoorInfo[i][dZ] == 0.0) {
                return i;
          }
     }
     return MAX_DOOR;
}
Reply


Messages In This Thread
how to increase id number per create? - by drichie - 30.06.2013, 11:03
Re: how to increase id number per create? - by Macluawn - 30.06.2013, 11:05
Re: how to increase id number per create? - by WooTFTW - 30.06.2013, 11:09
Re: how to increase id number per create? - by drichie - 30.06.2013, 11:20
Re: how to increase id number per create? - by WooTFTW - 30.06.2013, 11:25
Re: how to increase id number per create? - by drichie - 30.06.2013, 11:35
Re: how to increase id number per create? - by Macluawn - 30.06.2013, 11:39
Re: how to increase id number per create? - by WooTFTW - 30.06.2013, 11:42
Re: how to increase id number per create? - by Universal - 30.06.2013, 11:52
Re: how to increase id number per create? - by Macluawn - 30.06.2013, 12:39

Forum Jump:


Users browsing this thread: 3 Guest(s)