25.12.2011, 15:31
mpickup and dropickup are variables which hold numbers, the ids of the pickups
As said before they only hold these numbers and are not connected to the pickup itself
means that it could happen that the id which got hold in one of these variables will be created again
Just an easy example
What you could do now
1. Just set the variable under DestroyPickup to something invalid
2. Or you just write a constum function which does it for you
As said before they only hold these numbers and are not connected to the pickup itself
means that it could happen that the id which got hold in one of these variables will be created again
Just an easy example
pawn Код:
new
pickup1 = CreatePickup(); // lets say this is pickupid 1
DestroyPickup(pickup1); // destroy pickup1, pickupid 1 is now unused
new
pickup2 = CreatePickup(); // this would again create a pickup with the id 1
// now lets check for the pickups
if(pickup1 == 1) {
// this code will get executed
return 1;
}
if(pickup2 == 1) {
// this not
return 1;
}
1. Just set the variable under DestroyPickup to something invalid
pawn Код:
new
pickup1 = CreatePickup();
DestroyPickup(pickup1);
pickup1 = -1; // sets the variable to something invalid
new
pickup2 = CreatePickup();
if(pickup1 == 1) {
return 1;
}
if(pickup2 == 1) {
// this code will get executed
return 1;
}
pawn Код:
// this code needs to be over the first usage of DestroyPickup! (important)
stock DestroyPickupFully(&pickupid) {
if(DestroyPickup(pickupid)) {
pickupid = -1;
return true;
}
return false;
}
#define DestroyPickup DestroyPickupFully
pawn Код:
new
pickup1 = CreatePickup();
DestroyPickup(pickup1); // destroy pickup1, additionally sets pickup1 to -1 within the function
new
pickup2 = CreatePickup();
if(pickup1 == 1) {
return 1;
}
if(pickup2 == 1) {
// this code will get executed
return 1;
}