Raised This Month: $ Target: $400
 0% 

if condition for comparing indexed array to number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Owyn
Veteran Member
Join Date: Nov 2007
Old 02-11-2009 , 13:42   if condition for comparing indexed array to number
Reply With Quote #1

new array[32] // (array value is number 7)

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

but this does not work, correct me plz
Owyn is offline
Send a message via ICQ to Owyn
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-11-2009 , 13:45   Re: if condition for comparing indexed array to number
Reply With Quote #2

Should work, show the full code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 02-11-2009 , 14:03   Re: if condition for comparing indexed array to number
Reply With Quote #3

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

Last edited by Owyn; 02-11-2009 at 14:05.
Owyn is offline
Send a message via ICQ to Owyn
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-11-2009 , 14:10   Re: if condition for comparing indexed array to number
Reply With Quote #4

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")
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 02-11-2009 , 14:12   Re: if condition for comparing indexed array to number
Reply With Quote #5

yup, i was reading funcwiki for str_to_num and found same, but can't condition "if" work with indexed arrays?
Owyn is offline
Send a message via ICQ to Owyn
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 02-11-2009 , 14:54   Re: if condition for comparing indexed array to number
Reply With Quote #6

Quote:
Originally Posted by .Owyn. View Post
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.
__________________

Community / No support through PM
danielkza 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 16:53.


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