Are arrays of strings possible?
#1

I'm trying to do something like this:

Код:
new crimeArray[10]={"Reckless Driving", "Vehicular Homicide", "vehicular manslaughter", "vehicular assault",
					 "hit and run", "water eluding", "air eluding", "rTest"};
But from what I understand about pawn arrays, each index slot gets one character of each string. Is it possible to do something like what I'm trying to achieve here?
Reply
#2

Yes, you can.
Try this:
Код:
new crimeArray[8][32]={ {"Reckless Driving"}, {"Vehicular Homicide"}, {"vehicular manslaughter"}, {"vehicular assault"}, {"hit and run"}, {"water eluding"}, {"air eluding"}, {"rTest"} };
Reply
#3

Fortunately, PAWN (much like any other computer language) supports bi or even tri dimensional arrays, allowing you to store extra data on different indexes on different dimensions!.

For the example Borg posted, the first dimension would represent the index of each text, and the second dimension would store the characters of each string (with a max of 32).
Reply
#4

Quote:
Originally Posted by admantis
Посмотреть сообщение
Fortunately, PAWN (much like any other computer language) supports bi or even tri dimensional arrays, allowing you to store extra data on different indexes on different dimensions!.

For the example Borg posted, the first dimension would represent the index of each text, and the second dimension would store the characters of each string (with a max of 32).
That is correct.

Here's some more description:

pawn Код:
new crimeArray[8][32] = {
    {"Reckless Driving"}, // Can be accessed with "crimeArray[0]"
    {"Vehicular Homicide"}, // Can be accessed with "crimeArray[1]"
    {"vehicular manslaughter"}, // Can be accessed with "crimeArray[2]"
    {"vehicular assault"}, // Can be accessed with "crimeArray[3]"
    {"hit and run"}, // Can be accessed with "crimeArray[4]"
    {"water eluding"}, // Can be accessed with "crimeArray[5]"
    {"air eluding"}, // Can be accessed with "crimeArray[6]"
    {"rTest"} // Can be accessed with "crimeArray[7]"
};

//----In some function or callback
new cStr[128];
format(cStr, sizeof(cStr), "You are being charged with %s, and you will only be let out of jail if you are bailed out by another player. The bail price is $%d.", crimeArray[3], 5600);
cStr would equal:
You are being charged with vehicular assault, and you will only be let out of jail if you are bailed out by another player. The bail price is $5600.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)