Author Topic: Checking if a string equals x or y with out typing it out loads.  (Read 1912 times)

I know how to check strings ($=) but is there a way to check if a string equals "x" or "y" without typing it out again like if(%x && (%y || %z)){}, I tried if(%x $= ("x" || "y"){} in console but it didn't seem to work.

My only guess would be to not use parenthesis around the values to check, I.e:
if(%x $= "x" || "y") { //do stuff }
Either that, or perhaps just try boolean values, if you are only checking for one of 2 things?

if($string$=%x || $string$=%y){}

I know how Oxcorp I just wanted to know if you could check without typing out the variable again.

The only way I can think of doing it is the following:

(Only useful if you need to check large amounts of strings.)

Code: [Select]
%string[0] = <value>;
%string[1] = <value>;
%string[...] = <value>;

for(%i = 0; %i <= ...; %i++)
{
     if(%string[%i] $= <test value>)
     {
          //desired actions to take place if true
     }
}

I was just seeing to make my code look neater, if there's not anoter way I guess I'll just carry on with the long way.

Yeah, as far as I know, there's no way to do it with less code than this:
Code: [Select]
if(%a $= %b || %a $= %c)

Mhm, I'll just carry on that way unless someone knows a way.

lol, I don't get what your trying to do.  You mean something like this?

Code: [Select]
$Something = "11";
$Something2 = "11";
if($Something == $Something2)
{
echo("It's the same!");
}

I wanted to know if there was an easy way of typing out
if(%string $= "First" || %string $= "Second"){}

I wanted to know if there was an easy way of typing out
if(%string $= "First" || %string $= "Second"){}
are you seriously that lazy?

I wanted to know if there was an easy way of typing out
if(%string $= "First" || %string $= "Second"){}
are you seriously that lazy?

Yes.

Code: [Select]
function schk(%compare,%a,%b,%c,d,e){
if(%compare$=%a||%compare$=%b||%compare$=c||%compare$=d||%compare$=e){
return 1;
}else{
return 0;
}
}

then you can just use
Code: [Select]
if(cschk(%str,%x,%y))

Code: [Select]
function schk(%compare,%a,%b,%c,d,e){
if(%compare$=%a||%compare$=%b||%compare$=c||%compare$=d||%compare$=e){
return 1;
}else{
return 0;
}
}

then you can just use
Code: [Select]
if(cschk(%str,%x,%y))
I was gunna post that but I figured there's no point in having to type all that and in the end only using it once or twice, I don't find it that hard to do it the other way.

I'd use it about 10 times in my terrorist mod cause there's like 4 strings to check in most of commands.