[HELP] Pickup mixing with each other!
#3

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
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;
}
What you could do now

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;
}
2. Or you just write a constum function which does it for you
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;
}
Reply


Messages In This Thread
[HELP] Pickup mixing with each other! - by fiki574 - 25.12.2011, 13:49
Re: [HELP] Pickup mixing with each other! - by fiki574 - 25.12.2011, 14:26
AW: [HELP] Pickup mixing with each other! - by Nero_3D - 25.12.2011, 15:31
Re: [HELP] Pickup mixing with each other! - by fiki574 - 25.12.2011, 16:10

Forum Jump:


Users browsing this thread: 1 Guest(s)