View Full Version : Array of strings issue.
Firstly, I'd like to say that sourcepawn is a crap language.
As for my question:
How can I fix my code? I'm receiving the following errors:
new String:levelMaps[100][40];
inSomeFunc()
{
// array sizes do not match, or are too small
levelMaps[count] = mapName;
// array must be indexed.
if (levelMaps[i] == currentMap)
}
Thanks
I think I've solved the first issue. Is this the best way to do it?
strcopy(levelMaps[count], sizeof(levelMaps[]), mapName);
edit: and the second issue too:
strcmp(levelMaps[i], currentMap, false)
Powerlord
12-29-2011, 09:53
SourcePawn definitely shows its C roots when dealing with strings.
Anyway, strcopy for assigning values to a string is correct. You may want to use StrEquals instead of strcmp since StrEquals returns a bool. However, it's likely that StrEquals just calls strcmp internally anyway.
McFlurry
12-29-2011, 14:34
Yup StrEqual is just strcmp with a != -1 attached to the return.
Powerlord
12-29-2011, 15:58
Yup StrEqual is just strcmp with a != -1 attached to the return.
Should I even point out how that can't possible be correct? :P
I'm pretty sure you meant to say "StrEqual is just strcmp with a == 0 attached to the return" since -1 is only returned if the second argument is before the first alphabetically; 1 is returned if the second argument is after the first alphabetically.
McFlurry
12-29-2011, 16:37
Oh nevermind, I don't know where I got that idea anymore. :P
SourcePawn definitely shows its C roots when dealing with strings.
Yeah I noticed. It would have been better if it was more based on C++ with proper data types and strings.
You may want to use StrEquals instead of strcmp since StrEquals returns a bool. However, it's likely that StrEquals just calls strcmp internally anyway.
Thanks! Will use that instead.
rhelgeby
01-01-2012, 06:11
Check out the Pawn Language Guide (compuphase.com/pawn/Pawn_Language_Guide.pdf). It explains pretty much anything about the language, stuff that's not covered in the forum or wiki pages.
Check out the Pawn Language Guide (http://compuphase.com/pawn/Pawn_Language_Guide.pdf). It explains pretty much anything about the language, stuff that's not covered in the forum or wiki pages.
Thanks, it looks fairly comprehensive.
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.