Enum with two dimensional string -
ax1 - 15.10.2017
Код:
const hStorage_size1 = 20; // amount of members
const hStorage_size2 = MAX_PLAYER_NAME; // player name size
const sizeof_hStorage = hStorage_size1 * hStorage_size2;
enum Data
{
MemberName[sizeof_hStorage],
};
new GroupInfo[1000][Data];
#define hStorage][%1][%2] hStorage][((%1)*hStorage_size2)+(%2)]
CMD:name(playerid)
{
format(GroupInfo[21][MemberName][0], MAX_PLAYER_NAME, "Message");
return 1;
}
CMD:pr(playerid)
{
for(new g=0; g<20; g++)
{
new string[64];
format(string, sizeof(string), "%s", GroupInfo[21][MemberName][g]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
this is what I get after typing /name and /pr
Код:
[12:55:01] Message
[12:55:01] essage
[12:55:01] ssage
[12:55:01] sage
[12:55:01] age
[12:55:01] ge
[12:55:01] e
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
[12:55:01]
anyone know where the problem is? GroupInfo[21][MemberName][1] should be " ", but instead it's "essage"
I did this according to this tutorial
https://sampforum.blast.hk/showthread.php?tid=373107
Re: Enum with two dimensional string -
ax1 - 17.10.2017
bumping
Re: Enum with two dimensional string -
StrikerZ - 17.10.2017
PHP код:
MemberName[sizeof_hStorage]
That's a string, if you format it like for example
"Message", it has 7 letters, so MemberName[0], MemberName[1], .......... MemberName[6] would be occupied by the letters of "Message".
And the thing explained in the thread is 2-dimensional arrays in enum, but your's is 1 dimensional.
MemberName[0][0] <- 2 dimensional
MemberName[0] <- 1 dimensional
You can use the 2 dimensional as this
PHP код:
CMD:name(playerid)
{
format(GroupInfo[21][MemberName][6][0], MAX_PLAYER_NAME, "Message");
return 1;
}
CMD:pr(playerid)
{
for(new g=0; g<20; g++)
{
new string[64];
format(string, sizeof(string), "%s", GroupInfo[21][MemberName][g][0]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
Another thing to change is
PHP код:
#define hStorage][%1][%2] hStorage][((%1)*hStorage_size2)+(%2)]
to
PHP код:
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)]
Understood?
Re: Enum with two dimensional string -
ax1 - 17.10.2017
Quote:
Originally Posted by Sunehildeep
PHP код:
MemberName[sizeof_hStorage]
That's a string, if you format it like for example
"Message", it has 7 letters, so MemberName[0], MemberName[1], .......... MemberName[6] would be occupied by the letters of "Message".
And the thing explained in the thread is 2-dimensional arrays in enum, but your's is 1 dimensional.
MemberName[0][0] <- 2 dimensional
MemberName[0] <- 1 dimensional
You can use the 2 dimensional as this
PHP код:
CMD:name(playerid)
{
format(GroupInfo[21][MemberName][6][0], MAX_PLAYER_NAME, "Message");
return 1;
}
CMD:pr(playerid)
{
for(new g=0; g<20; g++)
{
new string[64];
format(string, sizeof(string), "%s", GroupInfo[21][MemberName][g][0]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
Another thing to change is
PHP код:
#define hStorage][%1][%2] hStorage][((%1)*hStorage_size2)+(%2)]
to
PHP код:
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)]
Understood?
|
I do not necessarily want 2-dimensional arrays in enum, I just want string array in enum and I thought that I could do that with 2 dimensional array

I cant do it like this
enum Data
{
MemberName[20][MAX_PLAYER_NAME]
};
because it brings me error
Re: Enum with two dimensional string -
ax1 - 18.10.2017
bump
Re: Enum with two dimensional string -
StrikerZ - 18.10.2017
Quote:
Originally Posted by ax1
I do not necessarily want 2-dimensional arrays in enum, I just want string array in enum and I thought that I could do that with 2 dimensional array  I cant do it like this
enum Data
{
MemberName[20][MAX_PLAYER_NAME]
};
because it brings me error
|
You don't need to do like that, because we've done this to obtain that.
PHP код:
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)]
So just, put this in enum.
PHP код:
enum Data
{
MemberName[sizeof_hStorage]
};
Re: Enum with two dimensional string -
ax1 - 18.10.2017
Quote:
Originally Posted by Sunehildeep
You don't need to do like that, because we've done this to obtain that.
PHP код:
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)]
So just, put this in enum.
PHP код:
enum Data
{
MemberName[sizeof_hStorage]
};
|
I get the same result : "Message" "essage" and so on
Re: Enum with two dimensional string -
Mauzen - 18.10.2017
Enums just cant contain 2D arrays. Thats a limitation of pawn. Possibly YSI got some workaround for that though, give it a look.
Quote:
Originally Posted by ax1
anyone know where the problem is? GroupInfo[21][MemberName][1] should be " ", but instead it's "essage"
|
Thats because MemberName is just a regular string in your code, so [MemberName][1] refers to the substring of it starting at position 1, thus it skips the 'M'.
hStorage in the #define is the name of an enum element in the example. You need to change it to the name of you pseudo-2d-array name: MemberName
Код:
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)]
Re: Enum with two dimensional string -
ax1 - 19.10.2017
So there's no way to put array string in enum?
#define MemberName][%1][%2] MemberName][((%1)*hStorage_size2)+(%2)] doesn't work