Question regarding strings inside arrays
#1

Alright so I havent scripted for in pawn for a loooong ass time, like six months or something. Now I forgot some of the things, trying to kick back and re-learn most of it.

Now I've stumbled across a weird issue I cannot seem to resolve and that is packing stuff into an array.

pawn Код:
#define MAX_LANGUAGES 2
enum PLAYER_INFO {
    Language[MAX_LANGUAGES],
};
new pInfo[MAX_PLAYERS][PLAYER_INFO];
   
format(pInfo[playerid][Language][0], 10, "English");
format(pInfo[playerid][Language][1], 10, "Russian");

for(new i=0; i < MAX_LANGUAGES; i++) {
    printf("%i %s",i,pInfo[playerid][Language][i]);
}

And the output seems to be
Код:
0 ERussian
1 Russian
Why isnt it pushing English into 0?
Reply
#2

pawn Код:
enum PLAYER_INFO {
    Language[10],
};
pawn Код:
#define MAX_LANGUAGES 2
enum PLAYER_INFO {
    Language[10],
};
new pInfo[MAX_PLAYERS][PLAYER_INFO];
   
format(pInfo[playerid][Language], 10, "English");
format(pInfo[playerid][Language], 10, "Russian");
Reply
#3

That does make sense haha, thanks mate +rep


EDIT: That still makes output be same, well not the same but its Russian Russian now.

Код:
	format(pInfo[playerid][Language], 10, "English");
	format(pInfo[playerid][Language], 10, "Russian");

	for(new i=0; i < MAX_LANGUAGES; i++) {
	    printf("%i %s",i,pInfo[playerid][Language]);
	}
same goes if I do
Код:
pInfo[playerid][Language][i]
Reply
#4

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
That does make sense haha, thanks mate +rep


EDIT: That still makes output be same, well not the same but its Russian Russian now.

Код:
	format(pInfo[playerid][Language], 10, "English");
	format(pInfo[playerid][Language], 10, "Russian");

	for(new i=0; i < MAX_LANGUAGES; i++) {
	    printf("%i %s",i,pInfo[playerid][Language]);
	}
same goes if I do
Код:
pInfo[playerid][Language][i]
What you're trying to do doesn't make much sense.

But if you want to store both strings:
pawn Код:
enum PLAYER_INFO {
    language_1[10],
    language_2[10]
};
new pInfo[MAX_PLAYERS][PLAYER_INFO];
   
format(pInfo[playerid][language_1], 10, "English");
format(pInfo[playerid][language_2], 10, "Russian");
Reply
#5

Yeah I do want to store both strings but it is possible to store them inside of an array instead of 2 variables?

ie:

Language[0] = English
Language[1] = Russian
Reply
#6

Or how about this?

Код HTML:
#define MAX_LANGUAGES 2
enum PLAYER_INFO {
	Language[MAX_LANGUAGES][10],
};
new pInfo[MAX_PLAYERS][PLAYER_INFO];
	
format(pInfo[playerid][Language][0], 10, "English");
format(pInfo[playerid][Language][1], 10, "Russian");

for(new i=0; i < MAX_LANGUAGES; i++) {
	printf("%i %s",i,pInfo[playerid][Language][i]);
}
Reply
#7

Quote:
Originally Posted by thefirestate
Посмотреть сообщение
Or how about this?

Код HTML:
#define MAX_LANGUAGES 2
enum PLAYER_INFO {
	Language[MAX_LANGUAGES][10],
};
new pInfo[MAX_PLAYERS][PLAYER_INFO];
	
format(pInfo[playerid][Language][0], 10, "English");
format(pInfo[playerid][Language][1], 10, "Russian");

for(new i=0; i < MAX_LANGUAGES; i++) {
	printf("%i %s",i,pInfo[playerid][Language][i]);
}
Not supported.
Reply
#8

I guess Ill just do with the language_1 and 2 for now, thanks bro.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)