Else error?!
#1

Hi, i have this:
pawn Код:
public CustomPickups()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if (PlayerToPoint(3, i,2026.4064,1017.9352,10.8203)) // Bank
    {
  GameTextForPlayer(i, "~y~Vitaj v ~y~Banke~n~~w~Napis /enterbank aby si vosiel dnu", 5000, 5);
  printf("Vitajvbanke");
    }
    else{
    if (PlayerToPoint(2, i,1315.3907,1436.6250,55.0039)) //Raketa
    {
  GameTextForPlayer(i, "~y~Houhouhou skuska", 5000, 5);
  printf("Vitajvbanke");
    }
    }
    else{ --- HERE IS ERROR BUT DONT KNOW HOW TO FIX IT!
    if (PlayerToPoint(2, i,1456.3907,1789.6250,255.0039)) //asd
    {
  GameTextForPlayer(i, "~y~asd", 5000, 5);
  printf("asd");
    }
    }
    }
    return 1;
}
Error:
Код:
D:\SA-MPS~1\GAMEMO~1\Max3.pwn(6312) : error 029: invalid expression, assumed zero
Help pls
Reply
#2

when using else if, its supposed to look like this:
pawn Код:
if(Function1()) // if this is wrong, else will be called, unless there is a else if.
{
  return true;
}
else if(Function2())
{
  return false;
}
else
{
  return false;
}
You wouldn't do what you have done, which is:
pawn Код:
if(Function1())
{
  return true;
}
else
{
  if(Function2())
  {
    return false;
  }
}
The above example WOULD work, but isn't necessary, yours wont work, because there is no DOUBLE ELSE with the same condution. So when ever IF is not what you want it to be, else will be called, UNLESS, there is a else if.
Reply
#3

Quote:
Originally Posted by [NT
Extremo ]
when using else if, its supposed to look like this:
pawn Код:
if(Function1()) // if this is wrong, else will be called, unless there is a else if.
{
 return true;
}
else if(Function2())
{
  return false;
}
else
{
  return false;
}
You wouldn't do what you have done, which is:
pawn Код:
if(Function1())
{
  return true;
}
else
{
  if(Function2())
  {
    return false;
  }
}
The above example WOULD work, but isn't necessary, yours wont work, because there is no DOUBLE ELSE with the same condution. So when ever IF is not what you want it to be, else will be called, UNLESS, there is a else if.
So... can i use a lot of else if and it will work?
Reply
#4

Quote:
Originally Posted by max007
Quote:
Originally Posted by [NT
Extremo ]
when using else if, its supposed to look like this:
pawn Код:
if(Function1()) // if this is wrong, else will be called, unless there is a else if.
{
 return true;
}
else if(Function2())
{
  return false;
}
else
{
  return false;
}
You wouldn't do what you have done, which is:
pawn Код:
if(Function1())
{
  return true;
}
else
{
  if(Function2())
  {
    return false;
  }
}
The above example WOULD work, but isn't necessary, yours wont work, because there is no DOUBLE ELSE with the same condution. So when ever IF is not what you want it to be, else will be called, UNLESS, there is a else if.
So... can i use a lot of else if and it will work?
+ Can u pls post an example of mine script that would work?
Reply
#5

You can use as much else if's as you want. Here is the example of how to fix your code:

pawn Код:
public CustomPickups()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if (PlayerToPoint(3, i,2026.4064,1017.9352,10.8203)) // Bank
        {
             GameTextForPlayer(i, "~y~Vitaj v ~y~Banke~n~~w~Napis /enterbank aby si vosiel dnu", 5000, 5);
             printf("Vitajvbanke");
         }
    }
    else if (PlayerToPoint(2, i,1315.3907,1436.6250,55.0039)) //Raketa
    {
        GameTextForPlayer(i, "~y~Houhouhou skuska", 5000, 5);
        printf("Vitajvbanke");
    }
    else if (PlayerToPoint(2, i,1456.3907,1789.6250,255.0039)) //asd
    {
        GameTextForPlayer(i, "~y~asd", 5000, 5);
        printf("asd");
    }
    else
    {
        return true;
    }
}
Reply
#6

the error was caused because you had "else {} else {}" if you would had intend your code you would have known

This is your version fixed
pawn Код:
public CustomPickups()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if (PlayerToPoint(3, i,2026.4064,1017.9352,10.8203)) // Bank
        {
            GameTextForPlayer(i, "~y~Vitaj v ~y~Banke~n~~w~Napis /enterbank aby si vosiel dnu", 5000, 5);
            printf("Vitajvbanke");
        }
        else
        {
            if (PlayerToPoint(2, i,1315.3907,1436.6250,55.0039)) //Raketa
            {
                GameTextForPlayer(i, "~y~Houhouhou skuska", 5000, 5);
                printf("Vitajvbanke");
            }
            else
            {
                if (PlayerToPoint(2, i,1456.3907,1789.6250,255.0039)) //asd
                {
                    GameTextForPlayer(i, "~y~asd", 5000, 5);
                    printf("asd");
                }
            }
        }
    }
    return 1;
}
And this is the version with else if
pawn Код:
public CustomPickups()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if (PlayerToPoint(3, i,2026.4064,1017.9352,10.8203)) // Bank
        {
            GameTextForPlayer(i, "~y~Vitaj v ~y~Banke~n~~w~Napis /enterbank aby si vosiel dnu", 5000, 5);
            printf("Vitajvbanke");
        }
        else if (PlayerToPoint(2, i,1315.3907,1436.6250,55.0039)) //Raketa
        {
            GameTextForPlayer(i, "~y~Houhouhou skuska", 5000, 5);
            printf("Vitajvbanke");
        }
        else if (PlayerToPoint(2, i,1456.3907,1789.6250,255.0039)) //asd
        {
            GameTextForPlayer(i, "~y~asd", 5000, 5);
            printf("asd");
        }
    }
    return 1;
}
This will both work but dont forgot both are different working codes
Reply
#7

The solution above was said by me already and to be honest, just to be a example, the first solution you have posted was stupid, not to be offensive but its just a waste of a if loop and the code will be slower then the code below. So from what i see, i would suggest the second option and not the first.
Reply
#8

Thx!

1 more question, i had a timers on 1 sec (autogates check...) and had about 12 gates but it was fucking up a server (1 player = 2mbps) if i will have only one function(and not 12) like this which timer will check every 1sec, and there will be all 12 autocheck gates (in one function, not 12 functions...) will it still fuck up server or not?
Reply
#9

Hi i have another problem....
pawn Код:
public CustomPickups()
{
new playerid;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if (PlayerToPoint(3, i,2026.4064,1017.9352,10.8203)) // Bank
        {
            GameTextForPlayer(i, "~y~Vitaj v ~y~Banke~n~~w~Napis /enterbank aby si vosiel dnu", 5000, 5);
            printf("Vitajvbanke");
        }
        /////////////////////////////////////////
        else if (BackDoorAdmin[playerid] ==1){
        {
        if(PlayerToPoint(10, i, -2016.614990, 484.523315, 31.420174) == 1) //make sure you have the PlayerToPoint function
        {
            MoveObject(sfgate, -2016.614990, 484.523315, 31.420174, 1); //if their in the area, open the game
            return 1; //and return so it don't move back when someone else isn't in the area
        }
        else
        {
            MoveObject(sfgate, -2016.613525, 484.558167, 36.958649, 1); //move back if no one is in the area
        }
        }
        }
        ///////////////////////////////////////////
        else if(IsPlayerAdmin(playerid)){
    {
        if(PlayerToPoint(10, i, -2016.614990, 484.523315, 31.420174) == 1) //make sure you have the PlayerToPoint function
        {
            MoveObject(sfgate, -2016.614990, 484.523315, 31.420174, 1); //if their in the area, open the game
            return 1; //and return so it don't move back when someone else isn't in the area
        }
        else
        {
            MoveObject(sfgate, -2016.613525, 484.558167, 36.958649, 1); //move back if no one is in the area
        }
        }
        }
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////!!!!!CANT ADD THIS BECOZ IT SAYS ERRORS
        else if(PlayerToPoint(10, i, -1571.80, 661.16, 6.08) == 1) //make sure you have the PlayerToPoint function
        {
            MoveObject(SFPDGATE, -1571.80, 654.16, 6.08, 1); //if their in the area, open the game
            return 1; //and return so it don't move back when someone else isn't in the area
            }
        else
        {
            MoveObject(SFPDGATE, -1571.80, 661.16, 6.08, 1); //move back if no one is in the area
        }
        //////////////////////////////////////////////// ^^^^^^^^^I CANT ADD THAT BECOZ THEN IT SAYS ERRORS.....
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        ////////////////////////////////////////////////
        else if (PlayerToPoint(10, i, -1631.78, 688.24, 8.68) == 1) //---6355
        {
            MoveObject(SFPDGATE2, -1631.78, 688.24, 13.68, 1); //if their in the area, open the game
            return 1; //and return so it don't move back when someone else isn't in the area
        }
        else
        {
            MoveObject(SFPDGATE2, -1631.78, 688.24, 8.68, 1); //move back if no one is in the area
        }
        /////////////////////////////////////////////////
    }
    return 1;
}
I canґt add anything to it... i think that return1; is doing that but dont know how to fix it :-X help pls..

Errors:
Код:
D:\SA-MPS~1\GAMEMO~1\Max3.pwn(6355) : error 029: invalid expression, assumed zero
D:\SA-MPS~1\GAMEMO~1\Max3.pwn(6355) : warning 215: expression has no effect
D:\SA-MPS~1\GAMEMO~1\Max3.pwn(6355) : error 001: expected token: ";", but found "if"
Reply
#10

Have another problem.. that isplayertopoint function lags server pls help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)