General Scripting Question
#1

I have a question with the below sample code. With the way that I have it set up, will the test(playerid); only be executed if the conditions of the if statement aren't met? If so, is there any way for test(playerid); to be executed without sticking it in the if statement to prevent redundancy. Obviously, sticking it in the if statement now isn't going to be matter since there isn't any other if statements in the function, but I'm talking as if there was.


Код:
public something(playerid)
{
   if(...)
   {
     ...
   }

   test(playerid);


}
Kind Regards,

Haku
Reply
#2

Hi,

The test(playerid) will be executed in all cases, because it's after the if statement, which does not exit the function something(playerid). (so script will keep running no matter if the conditions are met or not)
All of the examples below will be executed the way you wanted to. (if conditions are false, test the player)
pawn Код:
public something(playerid)
{
  if(...)
  {
    ...
  }
  else test(playerid);
}
// if ... is true, execute ..., any other cases, do test(playerid)
pawn Код:
public something(playerid)
{
  if(...)
  {
    ...
    return somevalue; // will exit the function, as you don't need to run test(playerid) if the conditions are met
  }
  test(playerid);
}
// If ... is true, execute ... and exit, if ... is false execute test(playerid)
pawn Код:
public something(playerid)
{
  if(!...) // note the '!', which is like ' == 0'
  {
    test(playerid);
    return somevalue; // will exit the function
  }
  ...
}
// if ... is false, execute test(playerid), and exit, if ... is true, execute ... only
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)