Raised This Month: $51 Target: $400
 12% 

Array of strings issue.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 12-29-2011 , 01:45   Array of strings issue.
Reply With Quote #1

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:

Code:
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
ceribik is offline
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 12-29-2011 , 01:49   Re: Array of strings issue.
Reply With Quote #2

I think I've solved the first issue. Is this the best way to do it?

Code:
strcopy(levelMaps[count], sizeof(levelMaps[]), mapName);
edit: and the second issue too:

Code:
strcmp(levelMaps[i], currentMap, false)

Last edited by ceribik; 12-29-2011 at 01:52.
ceribik is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-29-2011 , 09:53   Re: Array of strings issue.
Reply With Quote #3

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.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-29-2011 , 14:34   Re: Array of strings issue.
Reply With Quote #4

Yup StrEqual is just strcmp with a != -1 attached to the return.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-29-2011 , 15:58   Re: Array of strings issue.
Reply With Quote #5

Quote:
Originally Posted by McFlurry View Post
Yup StrEqual is just strcmp with a != -1 attached to the return.
Should I even point out how that can't possible be correct?

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-29-2011 at 15:58.
Powerlord is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-29-2011 , 16:37   Re: Array of strings issue.
Reply With Quote #6

Oh nevermind, I don't know where I got that idea anymore.
__________________

Last edited by McFlurry; 12-29-2011 at 16:38.
McFlurry is offline
Send a message via Skype™ to McFlurry
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 12-29-2011 , 19:21   Re: Array of strings issue.
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
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.

Quote:
Originally Posted by Powerlord View Post
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.
ceribik is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 01-01-2012 , 06:11   Re: Array of strings issue.
Reply With Quote #8

Check out the Pawn Language Guide. It explains pretty much anything about the language, stuff that's not covered in the forum or wiki pages.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 01-04-2012 , 21:10   Re: Array of strings issue.
Reply With Quote #9

Quote:
Originally Posted by rhelgeby View Post
Check out the Pawn Language Guide. It explains pretty much anything about the language, stuff that's not covered in the forum or wiki pages.
Thanks, it looks fairly comprehensive.
ceribik is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode