How to use brackets? [Tutorial]
#1

Hey.

I've seen a lot of people posting their scripts and having errors due to missed brackets. It is really simply to understand where you're supposed to put your brackets, as I've receieved a several PMs asking me what's wrong with their codes while brackets were missed.

My best suggestion is to count the brackets. E.g:
pawn Код:
//1    2         34
if(!strcmp(cmdtext,"/something"))
first bracket is if(.
2nd bracket is (cmdtext.
You just should count how much you have in code and when you close the code just add the same amount.
As you've seen we had two of brackets, if statement and before the "cmdtext", so it means we need to have two brackets to close.
another example:
pawn Код:
//1         2              3
if(IsPlayerInVehicle(playerid,GetPlayerVehicleID(playerid)))
after the if statement we have one bracket, before "playerid" another one, after "GetPlayerVehicleID" the last one. This means the code needs to be finished with three brackets ))).
if(IsPlayerInVehicle(playerid,GetPlayerVehicleID(playerid)))


Also people who've had 26 errors that weren't related to script errors, or their pawn got crashed, it usualy means missed brackets / too much brackets.

It goes the same about commands
pawn Код:
if(!strcmp(cmdtext,"/moveall"))
{// 1
  for(new i=0;i<MAX_PLAYERS;i++)
  { // 2
    if(!IsPlayerConnected(i))
      continue;
    SetPlayerPos(i,Float:x,Float:y,Float:z);
  } // we found two, we need to put in the same position and the same bracket but it must go to the other side "}"
  return 1; // to return the code
} // the closing bracket.
I hope it helped you, this topic used to make people stop posting topics about missed brackets, or 26 errors, or pawn crashes.
Reply
#2

Nice tutorial, clear and understandable. Is there a indenting tutorial becouse i am very bad indenting brackets.
Reply
#3

Isn't this enough? Two examples are also included.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)