SA-MP Forums Archive
enums, arrays halp. - 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)
+--- Thread: enums, arrays halp. (/showthread.php?tid=425005)



enums, arrays halp. - BigGroter - 24.03.2013

pawn Код:
CMD:open(playerid, params[])
{
    new Float:d[6];
    for(new i = 0; i != 6; ++i) {
        GetObjectPos(PlayerGates[i],d[0],d[1],d[2]); //line 859
        if(IsPlayerInRangeOfPoint(playerid, 5.0, d[0],d[1],d[2]))
        {
            MoveObject(PlayerGates[i],d[0],d[1],0,5.0,d[3],d[4],d[5]); //line 862
            break;
        }
    }
    return 1;
}
pawn Код:
//top of the script
enum pGates
{
    gate1,
    gate2,
    gate3,
    gate4,
    gate5
}

new PlayerGates[pGates];
Errors:
pawn Код:
(859) : warning 213: tag mismatch
(862) : warning 213: tag mismatch



Re: enums, arrays halp. - LarzI - 24.03.2013

Do you get the same warnings if you just create a normal 5-cell array? I can't remember any tags related to objects, but it seems that PlayerGates is the variable causing the errors.


Re: enums, arrays halp. - BigGroter - 24.03.2013

No, however as I said, this is the first time I try using arrays and enums, so I've most likely screwed something up.


Re: enums, arrays halp. - Vince - 24.03.2013

Took me a while to see this, but I just remembered that if you create a named enum, you essentially tag its members with that name. With that knowledge, you can either do:

pawn Код:
PlayerGates[pGates:i]
or
pawn Код:
PlayerGates[_:i]
or
pawn Код:
for(new pGates:i = 0; i != 6; ++i) {
Whichever you prefer.


Re: enums, arrays halp. - LarzI - 24.03.2013

Oh, sorry. I'm retarded. You're running a loop from 0 - 5 (6 indexes), while your array is only 5 indexes. You're also using the values 0 - 6 instead of "gate1", "gate2" and so on, so you really don't need the enum.

Just declare it as a normal array ([6] instead of [pGates]) unless you're going to use "gate1" and such to choose index. If you still want to use the enum, you have to put "pGates:" infront of the value, like so:

pawn Код:
PlayerGates[pGates:i]
Although I'm not entirely sure if that even works.

Ninja'd.


Re: enums, arrays halp. - BigGroter - 24.03.2013

Thank you.
I got it to work.