SA-MP Forums Archive
Else error?! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Else error?! (/showthread.php?tid=64748)



Else error?! - max007 - 07.02.2009

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



Re: Else error?! - Extremo - 07.02.2009

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.



Re: Else error?! - max007 - 07.02.2009

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?


Re: Else error?! - max007 - 07.02.2009

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?


Re: Else error?! - Extremo - 07.02.2009

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



Re: Else error?! - Nero_3D - 07.02.2009

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


Re: Else error?! - Extremo - 07.02.2009

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.


Re: Else error?! - max007 - 07.02.2009

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?


Re: Else error?! - max007 - 07.02.2009

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"



Re: Else error?! - max007 - 07.02.2009

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