Errors
#1

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?
Reply
#2

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);
Reply
#3

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?
Reply
#4

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]"
}
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)