AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   if condition for comparing indexed array to number (https://forums.alliedmods.net/showthread.php?t=85495)

Owyn 02-11-2009 13:42

if condition for comparing indexed array to number
 
new array[32] // (array value is number 7)

if (array[31] == 7)
{
action
}

but this does not work, correct me plz

ConnorMcLeod 02-11-2009 13:45

Re: if condition for comparing indexed array to number
 
Should work, show the full code.

Owyn 02-11-2009 14:03

Re: if condition for comparing indexed array to number
 
Code:

public client_connect(id)
{
    new rate[32]
    get_user_info(id, "rate", rate, 31)
    new rate2 = str_to_num( rate[31] );

    if ( rate[31] > 1 )
    {
    new name[32];
    get_user_name(id, name, 31);
   
    server_cmd("amx_chat ^"%s^"s rate is %s",name,rate);
    }

}

aslo, str_to_num doesn't work )= if i retrieve rate2 its data with %s i get get blank answer and with %d i get zero 0, rate (rate[32) returns fine with %s

ConnorMcLeod 02-11-2009 14:10

Re: if condition for comparing indexed array to number
 
new szRate[32]
get_user_info(id, "rate", szRate, charsmax( szRate ))
new iRate = str_to_num( szRate )

if( iRate < 10000 )
set_user_info(id, "rate", "10000")

Owyn 02-11-2009 14:12

Re: if condition for comparing indexed array to number
 
yup, i was reading funcwiki for str_to_num and found same, but can't condition "if" work with indexed arrays?

danielkza 02-11-2009 14:54

Re: if condition for comparing indexed array to number
 
Quote:

Originally Posted by .Owyn. (Post 760005)
yup, i was reading funcwiki for str_to_num and found same, but can't condition "if" work with indexed arrays?

It works fine. But you were trying to compare a char to an integer. The condition would only run if the char had the integer value of 7, which corresponds to the character 'BELL', and it's not even printable. You'd have to compare it to '7' for it to work, and it'd still be the wrong way.


All times are GMT -4. The time now is 16:53.

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