SA-MP Forums Archive
Errors - 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: Errors (/showthread.php?tid=622261)



Errors - GoldenLion - 20.11.2016

Hi, I'm creating a family system right now and I have 15 ranks for each family.
That's what my enumerator looks like:
Код:
enum familyInfo
{
	FamilyExists,
	FamilyName[32],
	FamilyStrikes,
	FamilyRanks,
	FamilyRank1[24],
	FamilyRank2[24],
	FamilyRank3[24],
	FamilyRank4[24],
	FamilyRank5[24],
	FamilyRank6[24],
	FamilyRank7[24],
	FamilyRank8[24],
	FamilyRank9[24],
	FamilyRank10[24],
	FamilyRank11[24],
	FamilyRank12[24],
	FamilyRank13[24],
	FamilyRank14[24],
	FamilyRank15[24]
}
new FamilyInfo[MAX_FAMILIES][familyInfo];
That's how I load the family info:
Код:
LoadFamilies()
{
	new string[24], rank[24];
	
	for (new i; i < MAX_FAMILIES; i++) if (dini_Exists(GetFamilyFile(i)))
	{
		format(FamilyInfo[i][FamilyName], 32, dini_Get(GetFamilyFile(i), "Name"));
		FamilyInfo[i][FamilyExists] = true;
		FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes")); //line 1670
		FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks"));
		
		for (new j = 1; j <= 15; j++)
		{
			format(string, sizeof(string), "Rank%d", j);
			format(rank, sizeof(rank), dini_Get(GetFamilyFile(i), string));
			
			format(string, sizeof(string), "FamilyRank%d", j);
			format(FamilyInfo[i][string], 24, rank);
		}
	}
}
And I get these errors:
Код:
(1670) : error 001: expected token: ";", but found ")"
(1670) : error 029: invalid expression, assumed zero
(1670) : warning 215: expression has no effect
(1671) : error 001: expected token: ";", but found ")"
(1671) : error 029: invalid expression, assumed zero
(1671) : warning 215: expression has no effect
(1679) : error 033: array must be indexed (variable "string")
I guess the line I marked is causing that as I don't see any mistakes in the code. Is that even possible to do it like that? That FamilyInfo[i][string] thing?
Or I can't load the ranks with a loop and I need to do it like that?:
Код:
format(FamilyInfo[i][FamilyRank1], 24, dini_Get(GetFamilyFile(i), "Rank1"));
format(FamilyInfo[i][FamilyRank2], 24, dini_Get(GetFamilyFile(i), "Rank2"));
format(FamilyInfo[i][FamilyRank3], 24, dini_Get(GetFamilyFile(i), "Rank3"));
...to be continued
I prefer a loop though. Anyways what's up?


Respuesta: Errors - Cerealguy - 20.11.2016

pawn Код:
FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes")); //line 1670
To
FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes"); //line 1670

FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks")); //line 1671
To
FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks");

AND

format(FamilyInfo[i][string], 24, rank); // string error

TO

format(FamilyInfo[i][string], 24, "%i", rank);



Re: Respuesta: Errors - GoldenLion - 20.11.2016

Quote:
Originally Posted by Cerealguy
Посмотреть сообщение
pawn Код:
FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes")); //line 1670
To
FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes"); //line 1670

FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks")); //line 1671
To
FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks");
Thanks for pointing that out, I didn't notice that. :P

Quote:
Originally Posted by Cerealguy
Посмотреть сообщение
pawn Код:
AND

format(FamilyInfo[i][string], 24, rank); // string error

TO

format(FamilyInfo[i][string], 24, "%i", rank);
Nope, rank is a string.

Anyways I removed two brackets and the only error I've got left is error 033: array must be indexed (variable "string") on this line: format(FamilyInfo[i][string], 24, rank);
I guess it's not possible to do it like that, is it?


Re: Errors - Konstantinos - 20.11.2016

The items in the enumerators are constants, not literal strings. If you do not modify the size of the ranks and/or add/remove ranks or add other items before the ranks (order), this will work:
pawn Код:
for (new index = 35; index <= 371; index += 24)
{
    // using "FamilyInfo[5][familyInfo: index]"
}



Re: Errors - GoldenLion - 20.11.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The items in the enumerators are constants, not literal strings. If you do not modify the size of the ranks and/or add/remove ranks or add other items before the ranks (order), this will work:
pawn Код:
for (new index = 35; index <= 371; index += 24)
{
    // using "FamilyInfo[5][familyInfo: index]"
}
What is it? Are there any tutorials about that or could you be so kind an explain it by yourself?. Mind blown lol.


Re: Errors - Konstantinos - 20.11.2016

It is the value of the index:
pawn Код:
printf("FamilyRank1: %i\nFamilyRank15: %i", FamilyRank1, FamilyRank15);

// output:
FamilyRank1: 35
FamilyRank15: 371
The size of the array is added to the next index so 35 + 24 (its size) = 59 which is the index of FamilyRank2 and so on.


Re: Errors - GoldenLion - 20.11.2016

Something like that?:
Код:
LoadFamilies()
{
	new string[24], rank[24], number;
	
	for (new i; i < MAX_FAMILIES; i++) if (dini_Exists(GetFamilyFile(i)))
	{
		format(FamilyInfo[i][FamilyName], 32, dini_Get(GetFamilyFile(i), "Name"));
		FamilyInfo[i][FamilyExists] = true;
		FamilyInfo[i][FamilyStrikes] = dini_Int(GetFamilyFile(i), "Strikes");
		FamilyInfo[i][FamilyRanks] = dini_Int(GetFamilyFile(i), "Ranks");
		
		for (new index = 35; index <= 371; index += 24)
		{
		        number++;
		    
			format(string, sizeof(string), "Rank%d", number);
			format(rank, sizeof(rank), dini_Get(GetFamilyFile(i), string));
			
			format(FamilyInfo[i][familyInfo:index], 24, rank);
		}
	}
}
That's how I understood how I need to do it. :P Or is there a better way? That number variable thing looks weird.


Re: Errors - Konstantinos - 20.11.2016

I can only think of the loop and normally writing 15 lines of it.

number will be 1-15 in every family and why don't you store to the array directly? Remove "number" from the top and:
pawn Код:
for (new index = 35, number = 1; index <= 371; index += 24, number++)
{
    format(string, sizeof(string), "Rank%d", number);
    strcat(FamilyInfo[i][familyInfo: index], dini_Get(GetFamilyFile(i), string), 24);
}
EDIT: Seems like the first index to reset cannot be used that way so if the server starts and load them, use strcat.


Re: Errors - GoldenLion - 20.11.2016

Thank you very much, but here is my last question: why is it bad to use format there and strcat is not?


Re: Errors - Konstantinos - 20.11.2016

https://sampforum.blast.hk/showthread.php?tid=309130