Lots of Errors
#1

Hello,

I'm trying to store all enter and exit coordinates into an enum so I don't have to IsPlayerInRangeOfPoint all the time for all the coordinates, but the problem is that I'm getting alot of errors, maybe you guys know the problem?

pawn Код:
enum EnterAndExitEnum
{
    Float:EnterPointX,
    Float:EnterPointY,
    Float:EnterPointZ,
    EnterText[128],
    Float:EnterCoordPointX,
    Float:EnterCoordPointY,
    Float:EnterCoordPointZ
}
new EnterAndExit[][EnterAndExitEnum] =
{
    {-116.8578, 1132.7495, 19.7375, "Test", 246.8042, 63.3659, 1003.6406}
};

CMD:enter(playerid, params[])
{
    new Float:EnterCoordx, Float:EnterCoordy, Float:EnterCoordz;
    EnterCoordx = EnterAndExit[EnterPointX];
    EnterCoordy = EnterAndExit[EnterPointY];
    EnterCoordz = EnterAndExit[EnterPointZ];
    if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterCoordx, EnterCoordy, EnterCoordz))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    return 1;
}
Код:
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2654) : warning 213: tag mismatch
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2654) : error 006: must be assigned to an array
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2655) : warning 213: tag mismatch
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2655) : error 032: array index out of bounds (variable "EnterAndExit")
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2655) : error 006: must be assigned to an array
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2656) : warning 213: tag mismatch
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2656) : error 032: array index out of bounds (variable "EnterAndExit")
C:\Users\Karim\Desktop\TRRP\gamemodes\TRRP.pwn(2656) : error 006: must be assigned to an array
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase
Reply
#2

1. You don't have to rewrite the variables
2. This is 2d array, not single dimensional, so you need to specify which element you are using:

pawn Код:
CMD:enter(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[0][EnterPointX], EnterAndExit[0][EnterPointY], EnterAndExit[0][EnterPointZ]))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
1. You don't have to rewrite the variables
2. This is 2d array, not single dimensional, so you need to specify which element you are using:

pawn Код:
CMD:enter(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[0][EnterPointX], EnterAndExit[0][EnterPointY], EnterAndExit[0][EnterPointZ]))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    return 1;
}
It worked, but now it will only check the first line of the enum right? I want to prevent doing this:
pawn Код:
CMD:enter(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[0][EnterPointX], EnterAndExit[0][EnterPointY], EnterAndExit[0][EnterPointZ]))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    else if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[1][EnterPointX], EnterAndExit[1][EnterPointY], EnterAndExit[1][EnterPointZ]))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    else if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[2][EnterPointX], EnterAndExit[2][EnterPointY], EnterAndExit[2][EnterPointZ]))
    {
        SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
        SetPlayerInterior(playerid, 6);
    }
    return 1;
}
So actually what I want is that I only need to do IsPlayerInRangeOfPoint once and it will check all the coordinates in the enum and then choose the coordinates where he is at.
Reply
#4

Almost perfect, but if you don't need any conditional logic, just use loop:
pawn Код:
CMD:enter(playerid, params[])
{
    for(new i = 0; i != sizeof EnterAndExit; ++i) {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[i][EnterPointX], EnterAndExit[i][EnterPointY], EnterAndExit[i][EnterPointZ]))
        {
            SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
            SetPlayerInterior(playerid, 6);
            return 1;
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Almost perfect, but if you don't need any conditional logic, just use loop:
pawn Код:
CMD:enter(playerid, params[])
{
    for(new i = 0; i != sizeof EnterAndExit; ++i) {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, EnterAndExit[i][EnterPointX], EnterAndExit[i][EnterPointY], EnterAndExit[i][EnterPointZ]))
        {
            SetPlayerPos(playerid, 246.8042, 63.3659, 1003.6406);
            SetPlayerInterior(playerid, 6);
            return 1;
        }
    }
    return 1;
}
Thank you for your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)