Convert something to an array.
#1

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?
Reply
#2

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
Reply
#3

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.
Reply
#4

@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
Reply
#5

Код:
#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?
Reply
#6

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

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
Reply
#8

Can you demonstrate please with PRICE_BAT?
Reply
#9

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)