AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Decision statements with strings? (https://forums.alliedmods.net/showthread.php?t=75707)

NewBKaeK 08-10-2008 16:34

Decision statements with strings?
 
I was wondering if this is possible, because for some reason I can't get it to work.

new Arg[32]
read_argv(1, Arg, 31)

if(Arg == 'string') { Do this }
else { Do this }

Am I doing something wrong in my code?
The error it gives me is: Array must be indexed (variable "Arg")

Thanks =]

atomen 08-10-2008 16:38

Re: Decision statements with strings?
 
PHP Code:

static string[] = "hello";

if(
equal(string"hello"))
{
 
// String was Hello
}

else if(
contain(string"he") != -1)
{
 
// The string contained "he"



Vet 08-10-2008 22:51

Re: Decision statements with strings?
 
What atomen is showing you is that you cannot compare strings with the == operator. You use the equal(), equali() or strcmp() functions.

For your example is would be:
new Arg[32]
read_argv(1, Arg, 31)

if(equali(Arg, "string")) { Do this }
else { Do this }


All times are GMT -4. The time now is 03:08.

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