SA-MP Forums Archive
Question regarding strings inside arrays - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question regarding strings inside arrays (/showthread.php?tid=621798)



Question regarding strings inside arrays - TwinkiDaBoss - 15.11.2016

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?


Re: Question regarding strings inside arrays - SickAttack - 15.11.2016

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");



Re: Question regarding strings inside arrays - TwinkiDaBoss - 15.11.2016

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]



Re: Question regarding strings inside arrays - SickAttack - 15.11.2016

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");



Re: Question regarding strings inside arrays - TwinkiDaBoss - 15.11.2016

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


Re: Question regarding strings inside arrays - thefirestate - 15.11.2016

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]);
}



Re: Question regarding strings inside arrays - SickAttack - 15.11.2016

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.


Re: Question regarding strings inside arrays - TwinkiDaBoss - 15.11.2016

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