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

Sourcemod need to compare 2 variables whithout index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-30-2015 , 10:02   Sourcemod need to compare 2 variables whithout index
Reply With Quote #1

Hi guys, i got a little problem, i need to compare 2 variables, but if i do this:

PHP Code:
new String:VARIABLE1[64] = SomeText1;
new 
String:VARIABLE2[64] = Text2;

if(
VARIABLE1 != VARIABLE2)
{
     
Some code if true or false

But compiler says, that VARIABLE1 and VARIABLE2 must be indexed, but i dont want to do that, i just want to compare 2 strings stored in variable.

Thanks in advance
Jcrr is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 07-30-2015 , 10:09   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #2

You can't compare strings like that, in pawn and many other languages where strings are "array like" you need to use some function.

StrEqual or strcmp

Last edited by KissLick; 07-30-2015 at 10:09.
KissLick is offline
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-30-2015 , 10:13   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #3

Ok, so it should be like this?
PHP Code:
stock bool:StrEqual(const String:VARIABLE1, const String:VARIABLE2bool:caseSensitive=true
How do i use it later? in
PHP Code:
if(somthing true)
{
    do 
somthing

Jcrr is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-30-2015 , 10:16   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #4

StrEqual is a stock that wraps a native in SM.
ex:
PHP Code:
if (StrEqual("LOL""L2")) { PrintToServer("I NO NEED!"); } 
__________________

Last edited by WildCard65; 07-30-2015 at 10:16.
WildCard65 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 07-30-2015 , 10:18   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #5

PHP Code:
new String:VARIABLE1[64] = SomeText1;
new 
String:VARIABLE2[64] = Text2;
if(
StrEqual(VARIABLE1VARIABLE2))
{
     
// VARIABLE1 is equal to VARIABLE2

KissLick is offline
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-30-2015 , 10:31   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #6

Ok, its working perfectly fine, thanks for help

Thread can be closed
Jcrr is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 07-30-2015 , 20:49   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #7

I didn't think you could assign a string's value like that. I was always told that you need to use Format (or FormatEx). That is interesting.
Marcus_Brown001 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-31-2015 , 09:54   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #8

Quote:
Originally Posted by Marcus_Brown001 View Post
I didn't think you could assign a string's value like that. I was always told that you need to use Format (or FormatEx). That is interesting.
Straight up assigning on strings can only be done inline when the variable is declared. Example:
PHP Code:
public void OnPluginStart()
{
    
char l1[] = "LOL"// Valid.
    //l1 = "L2"; // Invalid... Compile error.
    
Format(l1sizeof(l1), "L2"); //Valid... 1 of the different ways to re-assign a char array variable.

__________________

Last edited by WildCard65; 07-31-2015 at 09:55.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-31-2015 , 10:16   Re: Sourcemod need to compare 2 variables whithout index
Reply With Quote #9

You need to be careful when assigning strings as it can have unexpected side effects. That's why you should usually use strcopy or Format to assign things to strings.

The major exception is assigning a literal value (i.e. one that looks like "this")
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-31-2015 at 10:35.
Powerlord 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 20:26.


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