SA-MP Forums Archive
Convert something to an 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: Convert something to an array. (/showthread.php?tid=457455)



Convert something to an array. - RedJohn - 11.08.2013

Hey, how could I convert those:
pawn Код:
#define PRICE_BAT 11500
#define EMBED_PRICE_BAT "11500"
to an array.

I tried:

pawn Код:
new PRICE_BAT[2][2] = {
    {11500, "11500"}
};
but I get this error when I use it:

Код:
error 018: initialization data exceeds declared size
Usage:
pawn Код:
PRICE_BAT[0][0];
First 0 is for first array, seconds is for second column, is that right?


Re: Convert something to an array. - Emmet_ - 11.08.2013

Try this:

pawn Код:
enum arrayPrices
{
    priceInt,
    priceEmbed[12]
};

new PriceArray[][arrayPrices] =
{
    {11500, "11500"},
    {11501, "11501"}
};
And then use it like this:

pawn Код:
printf("%d", PriceArray[0][priceInt]); // 11500
printf("%d", PriceArray[1][priceInt]); // 11501



Re: Convert something to an array. - RedJohn - 11.08.2013

And what should I type for "11500"?

Not for integer, for string.

And what's this [12], what that describes?

EDIT:
I use integer for GivePlayerMoney, and string for embeding price into weapons dialog.


AW: Convert something to an array. - Nero_3D - 11.08.2013

@Emmet_

Using enums for constant data is a bad way because it creates a lot of empty cells!

@RedJohn

I would like to understand why you need something like that if you just could format the integer into a string with valstr or format


Re: Convert something to an array. - RedJohn - 11.08.2013

Код:
#define PRICE_BAT 11500
#define EMBED_PRICE_BAT "11500"
Код:
if(GetPlayerMoney(playerid) > PRICE_BAT)
{
    GivePlayerWeapon(playerid, 5, 100);
    GivePlayerMoney(playerid, -PRICE_BAT);
}
Код:
ShowPlayerDialog(playerid, DIALOG_AMMU_GUNS, DIALOG_STYLE_LIST, "Ammunation","Baseball Bat - $"EMBED_PRICE_BAT", "Buy", "Close");
Do you understand now?


AW: Convert something to an array. - BigETI - 11.08.2013

You would save memory, if you would use valstr() instead.


AW: Convert something to an array. - Nero_3D - 11.08.2013

I thought of that but than you missed out that something like that isn't possible with an array
You would need to use than format anyway, why not stick with that ?

Also instead of EMBED_PRICE_BAT you could do #PRICE_BAT


Re: Convert something to an array. - RedJohn - 11.08.2013

Can you demonstrate please with PRICE_BAT?


AW: Convert something to an array. - Nero_3D - 11.08.2013

pawn Код:
main() {
    #define PRICE_BAT 11500

    printf("%d = " #PRICE_BAT, PRICE_BAT); // "11500 = 11500"
}



Re: Convert something to an array. - RedJohn - 11.08.2013

So, #PRICE_BAT = String, PRICE_BAT = Integer. Right?