AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get current Map and use 'if' (https://forums.alliedmods.net/showthread.php?t=189542)

Veggetta 07-08-2012 08:50

Get current Map and use 'if'
 
Hello everybody,

today i want to do something like:

PHP Code:

new Name[32]
get_mapname(Namecharsmax(Name))
// And now i'm stuck with an error
if(Name == "cs_")
{
    function
}
else if(
Name == "de_")
{
   
Other Funtion


"Error: Array must be indexed (variable "Name") on line ..."
So what do i do to correct this ?

kiki33hun 07-08-2012 08:52

Re: Get current Map and use 'if'
 
Code:
new Name[32] get_mapname(Name, 31) if(equali(Name, "cs_") {     function } else if(equali(Name, "de_") {    Other Funtion }

Backstabnoob 07-08-2012 08:54

Re: Get current Map and use 'if'
 
You cannot use == operator with strings. Use equal(), equali(), contain(), containi() functions.

Veggetta 07-08-2012 08:54

Re: Get current Map and use 'if'
 
ahhh yes i forgot that x).
Thanks :D

t3hNox 07-08-2012 08:55

Re: Get current Map and use 'if'
 
To be more specific:
if(equali(szMapName, "de_", 3))

It only checks the first three characters (for example, "de_", not the whole map name "de_inferno").

guipatinador 07-08-2012 11:34

Re: Get current Map and use 'if'
 
Quote:

Originally Posted by kiki33hun (Post 1746023)
Code:

    new Name[32]
    get_mapname(Name, 31)
    if(equali(mapname, "cs_")
    {
        function
    }
    else if(equali(mapname, "de_")
    {
        Other Funtion
    }


Why you create the "Name" but then you use "mapname"?
You forget to close the parentheses in both "if"
t3hNox code is fine.

kiki33hun 07-08-2012 11:42

Re: Get current Map and use 'if'
 
Quote:

Originally Posted by guipatinador (Post 1746103)
Why you create the "Name" but then you use "mapname"?
You forget to close the parentheses in both "if"
t3hNox code is fine.

Edited^^

lucas_7_94 07-08-2012 13:35

Re: Get current Map and use 'if'
 
Code:
if( name[ 0 ] == 'c' && name[ 1 ] == 's' && name[ 2 ] == '_' ) cs_* map                    // do stuff if( name[ 0 ] == 'd' && name[ 1 ] == 'e' && name[ 2 ] == '_' ) de_* map                    // do stuff

fysiks 07-08-2012 13:38

Re: Get current Map and use 'if'
 
Quote:

Originally Posted by lucas_7_94 (Post 1746170)
Code:
if( name[ 0 ] == 'c' && name[ 1 ] == 's' && name[ 2 ] == '_' ) cs_* map                    // do stuff if( name[ 0 ] == 'd' && name[ 1 ] == 'e' && name[ 2 ] == '_' ) de_* map                    // do stuff

The two events are mutually exclusive so you need to take that into account. Also, for many newer people, it's easier to tell them to use equal[i].

mottzi 07-08-2012 14:47

Re: Get current Map and use 'if'
 
But that way it would be more efficiant, wouldnt it? :)


All times are GMT -4. The time now is 15:19.

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