SA-MP Forums Archive
Help me about array - 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: Help me about array (/showthread.php?tid=659048)



Help me about array - RichKiez - 21.09.2018

I'm having a problem

Код:
new Skin[] =
{
         1, 2, 4, 8, 9, 10, 11, 60, 91,
         92, 93, 94, 95, 96, 97, 98, 99,
         138, 140
};

CMD:checksizeof(playerid, params[])
{
         new string[128];
         format(string, sizeof(string), "Sizeof Skin: %d", sizeof(Skin[]));
         SendClientMessage(playerid, -1, string);
         return 1;
}
I get a return value of 1 (Sizeof Skin: 1) while sizeof must be 19 (Sizeof Skin: 19)


Re: Help me about array - UFF - 21.09.2018

Код:
CMD:checksizeof(playerid, params[])
{
         new string[128];
         format(string, sizeof(string), "Sizeof Skin: %d", sizeof(Skin));
         SendClientMessage(playerid, -1, string);
         return 1;
}



Re: Help me about array - Lokii - 21.09.2018

18 cells is enough you dont need 128


Re: Help me about array - VVWVV - 21.09.2018

You have one dimension array, so you don't need to use the square brackets in the sizeof operator. I also recommend that you use a 'static const' array to get the size of the string.

pawn Код:
CMD:foo(playerid, params[])
{
    static const fmt[] = "Sizeof skin: %d";
    new buffer[sizeof(fmt) + (-2 /* %d */ + 3 /*000*/ )];
    format(buffer, sizeof(buffer), fmt, sizeof(Skin));
    SendClientMessage(playerid, -1, buffer);
    return 1;
}



Re: Help me about array - RichKiez - 22.09.2018

Thank All