AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Easy way to check multiple equals? (https://forums.alliedmods.net/showthread.php?t=55904)

hlstriker 06-01-2007 18:08

Easy way to check multiple equals?
 
I'm trying to check to see if a variable is equal to different strings.

I know you can do...
Code:
equal(variable, "test");

How can I check to see if the variable is equal to multiple strings though?

Example that doesn't work but shows my question:
Code:
equal(variable, "test1", "test2", "test3", "test4", "etc...");

teame06 06-01-2007 18:12

Re: Easy way to check multiple equals?
 
There is no easy way to do it. You can put those variables into an 2d array. When ever you call that function you can use a for loop. Then check if that variable is equal to those string you want to check with variable.

With equal it can only check one string at a time. So you have to call it multiple times.

hlstriker 06-01-2007 18:24

Re: Easy way to check multiple equals?
 
I thought about a loop before I posted this, but wanted to check if anything easier was out there.

Thanks

Cheap_Suit 06-01-2007 18:43

Re: Easy way to check multiple equals?
 
Edit: What team06 describe.

PHP Code:

if(equal(variable"test1")
|| 
equal(variable"test2")
|| 
equal(variable"test3")
|| 
equal(variable"test4"))
{
//do stuff



v3x 06-01-2007 19:56

Re: Easy way to check multiple equals?
 
or:
PHP Code:

#include <amxmodx>

#define MAX_ITEMS 3

new g_items[MAX_ITEMS][] = 
{
    
"gaben",
    
"yams",
    
"turtles"
}

public 
test()
{
    for(new 
0MAX_ITEMSi++)
    {
        if(
equal("yams"g_items[i]))
        {
            
// found a match
        
}
    }



Rolnaaba 06-01-2007 20:00

Re: Easy way to check multiple equals?
 
v3x ur signiture is getting cut off


All times are GMT -4. The time now is 10:37.

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