SA-MP Forums Archive
Small question about returns - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Small question about returns (/showthread.php?tid=537850)



Small question about returns - biker122 - 18.09.2014

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, "");"?


Re: Small question about returns - IamPRO - 18.09.2014

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
}



Re: Small question about returns - biker122 - 18.09.2014

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


Re: Small question about returns - Stinged - 18.09.2014

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;
}



Re: Small question about returns - biker122 - 18.09.2014

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


Re: Small question about returns - IamPRO - 18.09.2014

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.


Re: Small question about returns - biker122 - 18.09.2014

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


Re: Small question about returns - Vince - 18.09.2014

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.


Re: Small question about returns - biker122 - 18.09.2014

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!