Small question about returns
#1

So, I've got a little question in a case;
What will happen if we return in dialogs, dynamic pickups, checkpoints, etc.
So, what's the difference here and what will happen here:
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == RandPick[0])
    {
        cmd_cnr(playerid,"");
        return 1;
             }
             return 1;
}
and here:
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == RandPick[0])
    {
        cmd_cnr(playerid,"");
    }
             return 1;
}
Will there be any difference if I return 1 inside after using that "cmd_cnr(playerid, "");"?
Reply
#2

Yes there is a difference:
in the first code.
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == RandPick[0])
    {
        cmd_cnr(playerid,"");
        return 1;//returning to 1 ( Ending OnPlayerPickUpDynamicPickup)
    }
    //code here will not be executed.
    return 1;//returning to 1
}
in the second code
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == RandPick[0])
    {
        cmd_cnr(playerid,"");
    }
    //whole code will be read when callback is called
    return 1;//returning to 1
}
Reply
#3

so consider that i have 30 pickups. Am I advised to return it to 1?
Reply
#4

pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == whatever)
    {
        // whatever
    }
    SendClientMessage(playerid, -1, "This message will be called when you pickup any pickup.");
    return 1;
}

public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == whatever)
    {
        // whatever
        return 1;
    }
    SendClientMessage(playerid, -1, "This message will NOT be called if you pickup the whatever pickup.");
    return 1;
}
Reply
#5

I understood that, My final question is: Should I return the pickups? or just leave it to go through the remaining stuff?
Reply
#6

If you don't want to use the code placed under this:
pawn Код:
if(pickupid == RandPick[0])
    {
        cmd_cnr(playerid,"");
        return 1;
    }
then you can use return 1, this will (maybe) take less time and less lagg.
Reply
#7

I think you haven't understood my question..
Should I return every pickup or no?
Reply
#8

Considering that you are using an array to keep track of them you should probably be using a loop rather than going through them sequentially. You only need to return if you want to end the function. If there is code that you want to execute, then don't put a return. It's rather simple, really.
Reply
#9

You cleared some of my confusions..
And for the pickups, The array size (RandPick) is 20, which is created on different locations, EACH OF THEM HAS A SEPARATE COMMAND TO EXECUTE. That's why I didn't use a loop for that.
Anyways, Thanks everyone for the replies!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)