AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Equality with array (https://forums.alliedmods.net/showthread.php?t=12514)

[WbOF]LuZiFeR 04-17-2005 06:05

Equality with array
 
A little noob-question :)

I use

Code:
new CC[15] get_user_ip(id,userip,31,1) geoip_country(userip,CC)

to catch a players country...

Now, i will compare this with a variable (i.e. "United States" )

Code:
if (CC == "United States") { }

But this is not the correct syntax (CC is a array i think)...

Because the following error occured:

Quote:

033 array must be indexed (variable name)
An array as a whole cannot be used in a expression; you must indicate
an element of the array between square brackets.
How is the correct syntax ?

I've read the Help-Files, but i don't understand some things... :)

thx in advance...

v3x 04-17-2005 06:08

Code:
new CC[15] get_user_ip(id,userip,31,1) new country = geoip_country(userip,CC) if(country == "United States") {     // .. }

[WbOF]LuZiFeR 04-17-2005 06:19

Thx for the fast answer, but it results in the same error:

Quote:

country_welcome.sma(108) : error 033: array must be indexed (variable "-unknown-")
Code now looks like this:

Code:
        register_cvar("sv_message","1")         g_message = get_cvar_num("sv_message")         new userip[32]         new CC[15]         get_user_ip(id,userip,31,1)         new countrygeo = geoip_country(userip,CC)          if(g_message == 1 && countrygeo == "United States")         { ....         }

v3x 04-17-2005 06:24

Oh, wow.. It worked just a minute ago.. I'll try to figure this out. :P

Edit:

Code:
public myFunc(id) {     new target = read_data(2)     new g_message = get_cvar_num("sv_message")     new ip[32]     new country[45]     get_user_ip(target,ip,31)     geoip_country(ip,country)     if(equal(country,"United States") && g_message == 1){         //...     }     return PLUGIN_HANDLED }
[EDITED]

[WbOF]LuZiFeR 04-17-2005 07:40

What does this function is returning back ?

And where do i set i.e. "United States" ? :)

Code:
if(myfunc(id)) == "United States") { }

??

v3x 04-17-2005 07:45

Grr, damnit.. Remind me not to post when I'm about to hit the Zzz's. It's that damned == "United States" part that is giving you the error about the index.

PM 04-17-2005 08:38

To compare strings, you have to use the equal native:

Code:

if (equal(CC, "United States"))
{
  // blabla!
}

A string is a null-terminated array of characters. equal goes through all the characters in CC, and compares them to the corresponding characters in the other argmuent.

v3x 04-17-2005 08:43

Now why didn't I think of that in the first place? :stupid:

WbO, take a look @ my updated code above.

[WbOF]LuZiFeR 04-17-2005 09:37

Thx for your efforts :)

Now it works fine :D YEEEHAAA....!!!

v3x 04-17-2005 09:39

Quote:

Originally Posted by [WbOF
LuZiFeR]Thx for your efforts :)

Now it works fine :D YEEEHAAA....!!!

Whoa there cowboy! :lol:


All times are GMT -4. The time now is 09:51.

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