Raised This Month: $ Target: $400
 0% 

Easy way to check multiple equals?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-01-2007 , 18:08   Easy way to check multiple equals?
Reply With Quote #1

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...");
hlstriker is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 06-01-2007 , 18:12   Re: Easy way to check multiple equals?
Reply With Quote #2

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.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-01-2007 , 18:24   Re: Easy way to check multiple equals?
Reply With Quote #3

I thought about a loop before I posted this, but wanted to check if anything easier was out there.

Thanks
hlstriker is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 06-01-2007 , 18:43   Re: Easy way to check multiple equals?
Reply With Quote #4

Edit: What team06 describe.

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

__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.

Last edited by Cheap_Suit; 06-01-2007 at 18:46.
Cheap_Suit is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 06-01-2007 , 19:56   Re: Easy way to check multiple equals?
Reply With Quote #5

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
        
}
    }

__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.

Last edited by v3x; 06-01-2007 at 19:58.
v3x is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 06-01-2007 , 20:00   Re: Easy way to check multiple equals?
Reply With Quote #6

v3x ur signiture is getting cut off
__________________
DO NOT PM me about avp mod.
Rolnaaba 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 10:37.


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