• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Post your code snippets here
#16
(2019-04-16, 11:23 AM)Y_Less Wrote:
(2019-04-14, 11:04 PM)DTV Wrote: I remember seeing a thread like this on SA-MP forums so it'd be nice to share with each other little tricks to making our lives easier with pawn, I'll start:

Actually don't know what this is formally called, but you can use it to skip parts of code when needed (good in a situation where the ending part of code is always the same but you don't need to copy/paste that code in every if/switch statement)
Code:
someFunc(params) {

? ? if(params) {

? ? ? ? SendClientMessage(playerid,-1,"Not skipped!");
? ? ? ? return 1;
? ? }

? ? else { goto skipBlock; } //this is how you'd call for the code to skip to `skipBlock`

? ? skipBlock: //this is how you'd create it

? ? SendClientMessage(playerid,-1,"Skipped!");
? ? return 1;
}

I'm not quite sure why this is trying to do.? It would be exactly the same without the majority of this code:

Code:
someFunc(params) {

? ? if(params) {

? ? ? ? SendClientMessage(playerid,-1,"Not skipped!");
? ? ? ? return 1;
? ? }

? ? SendClientMessage(playerid,-1,"Skipped!");
? ? return 1;
}

The "return" ends the function early, so only code that passes your first check prints "Skipped".

removed
  Reply


Messages In This Thread
Post your code snippets here - by DTV - 2019-04-14, 11:04 PM
RE: Post your code snippets here - by iSpark - 2019-04-15, 03:50 AM
RE: Post your code snippets here - by DTV - 2019-04-15, 07:07 AM
RE: Post your code snippets here - by BlackBank - 2019-04-15, 05:17 PM
RE: Post your code snippets here - by Codeah - 2019-04-15, 06:55 PM
RE: Post your code snippets here - by Riddick - 2019-04-16, 06:24 AM
RE: Post your code snippets here - by Y_Less - 2019-04-16, 11:23 AM
RE: Post your code snippets here - by DTV - 2019-04-16, 06:10 PM
RE: Post your code snippets here - by Grate Maharlika - 2020-10-19, 03:22 PM
RE: Post your code snippets here - by KJason - 2019-04-16, 11:48 AM
RE: Post your code snippets here - by kristo - 2019-04-16, 12:50 PM
RE: Post your code snippets here - by Mike - 2019-04-17, 02:45 AM
RE: Post your code snippets here - by DTV - 2019-04-29, 07:24 PM
RE: Post your code snippets here - by DTV - 2020-01-03, 06:33 PM
RE: Post your code snippets here - by Awide - 2020-10-18, 07:33 PM
RE: Post your code snippets here - by Expert* - 2020-10-24, 12:40 PM
RE: Post your code snippets here - by Virsenas - 2021-02-26, 11:53 PM
RE: Post your code snippets here - by Tama - 2021-10-27, 03:59 PM

Forum Jump: