Question about strings and arrays
#1

Ok this is a simple question I should have asked a long time ago.
In the format object what layer of array does it use to format the string or in GetPlayerName what layer does it get the name

is it like this
Код:
[MAX_PLAYER_NAME][MAX_SOMETHING][MAX_SOMETHINGELSE]
or
Код:
[MAX_SOMETHING][MAX_SOMETHINGELSE][MAX_PLAYER_NAME]
Reply
#2

[MAX_PLAYER_NAME] stands in fact for the maximum name length, it's like string[128].
pawn Код:
new string[128], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "Your name is %s", playername);
    SendClientMessage(playerid, -1, string);
This will show you a message saying your name.
Reply
#3

strings, and arrays are of the same thing. A string is just an array of characters. There is also single dimension, 2 dimensional, and 3 dimensional arrays in pawn.

example of a 1 dimensional array:
pawn Код:
new array[3] = {0, 1, 2};
essentially if you were looking at it like a table, you would see
[0][1][2]

or a 2 dimensional
pawn Код:
new array[2][3] = {
  {0, 1, 2},
  {3, 4, 5}
};
essentially if you were looking at it like a table, you would see
[0][1][2]
[3][4][5]

or 3-dimensional array
pawn Код:
new array[2][2][3] = {
  {{0, 1, 2},
    {3, 4, 5}},
  {{6, 7, 8},
    {9, 10, 11}},
}
this you can't really see as a table as it would be a 3-dimensional rectangle.

only difference between the string and those arrays is instead of number it's just a character. Ex 'A', 'B', 'C'

more info from a quick ****** search: https://sampforum.blast.hk/showthread.php?tid=318212
Reply
#4

I know what an array is but I was just wondering if the format method for a string uses the first or third dimension
Reply
#5

it depends what you specify. it will format what ever degree you specify. so if you had an array of names, for example
pawn Код:
new name_array[4][MAX_PLAYER_NAME];
that is essentially 4x32 array. so if you wanted format to format the last dimensions as your saying or the array id 2 in the array of names all you would have to do it
pawn Код:
format(name_array[2], sizeof(name_array[2]), "%s", "John_Doe");
or a 3-d example
pawn Код:
new name_array_3d[4][4][MAX_PLAYER_NAME];
format(name_array_3d[2][1], sizeof(name_array_3d[2][1]), "%s", "John_Doe");
and it will format to the 32 cells in cell 2-1.
Reply
#6

Alright thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)