потому что ты проверяешь не ячейки, а всё целиком. Конечно будет true. Потому что он (массив) существует.
|
К FALSE будет приводится любой из "", '', 0, null, false, EOL и даже в некоторых случаях "0". |
new test[2]; test = "0"; if(test[0]) // true
if(test || test1 == 1)
// делается только так
if(test == 3 || test1 == 3) // любое число заместо тройки
// а
if(test && test1 == 1)
// можно записать так
if(test == 5 == test1) // test и test1 = 5 (любое число заместо пятёрки)
if(test || test1) //test = положительно или test1 = положительно
if(test && test1) //test = положительно и test1 = положительно
if(test && !test1) //test = положительно и test1 = не положительно
if(test || !test1) //test = положительно или test1 = не положительно
// custom :D
if(test == 5 || !test1) //test = 5 или test1 = не положительно
Reim, не обращай внимания, парням дай повод - им крышу снесёт а на твой вопрос ответ будет такой:
PHP код:
Если тебе надо узнать между отрицательным и положительным значением, то можно записывать так: PHP код:
|
if(!test1)
Хотел бы спросить, есть ли у такой проверки какие либо минусы?
PHP код:
PHP код:
|
По поводу производительности - нано уровень.
ИМХО, конструкции лучше делать ступенчатой. 2 условия. Первый не сработал, то второй и вовсе не проверяем. Но опять же это нано уровень. |
Если одно условие не сработает, то последующие и так проверяться не будут же (если я правильно понял).
|
ИМХО, конструкции лучше делать ступенчатой. 2 условия. Первый не сработал, то второй и вовсе не проверяем. Но опять же это нано уровень. |
new test = 1;
new test1 = 0;
if(test || test1 == 1) SCM(i,-1,"WORK");
я вот к чему задал этот вопрос, просто при такой проверке сообщение "WORK" выводится
PHP код:
|
Нуу.. кое-кто заявил обратное, если я правильно понял.
Или Stepashka имел в виду проверку отдельного символа "0"? Мм Даже если так, то конструкция все равно вернет true. Код:
new test[2]; test = "0"; if(test[0]) // true |
new query[256];
mysql_format(MySQL_Handle, query, sizeof(query), "SELECT * FROM `%s` WHERE `player_name` = '%e' LIMIT 1", MySQL_TABLE_GENERAL, name);
mysql_tquery(MySQL_Handle, query, "OnPlayerDataLoaded");
forward OnPlayerDataLoaded()
public OnPlayerDataLoaded()
{
print("call OnPlayerDataLoaded");
}
Кто-нибудь работал с плагином от BlueG >> https://sampforum.blast.hk/showthread.php?tid=56564 ver. 39-2.
У меня ужасная проблема с методами mysql_tquery, mysql_pquery. Указанных в них callback[] на отрез отказывается вызываться... В логах как MySQL сервера, так и самого плагина всё хорошо, никаких ошибок. PHP код:
|
[17:29:24] [DEBUG] mysql_connect - host: "localhost", user: "rl_reincarnation", database: "rl_reincarnation", password: "****", port: 3306, autoreconnect: true, pool_size: 2 [17:29:24] [DEBUG] CMySQLHandle::Create - creating new connection.. [17:29:24] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called [17:29:24] [DEBUG] CMySQLHandle::Create - connection created (id: 1) [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] mysql_tquery - connection: 1, query: "SHOW VARIABLES LIKE "%version%";", callback: "OnPlayerDataLoaded", format: "d" [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLQuery::Execute[OnPlayerDataLoaded] - starting query execution [17:29:24] [DEBUG] CMySQLQuery::Execute[OnPlayerDataLoaded] - query was successfully executed within 0.651 milliseconds [17:29:24] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [17:29:24] [DEBUG] Calling callback "OnPlayerDataLoaded".. [17:29:24] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
141008 17:29:24 19 Connect rl_reincarnation@localhost on rl_reincarnation 19 Query SET NAMES utf8 20 Connect rl_reincarnation@localhost on rl_reincarnation 20 Query SET NAMES utf8 21 Connect rl_reincarnation@localhost on rl_reincarnation 21 Query SET NAMES utf8 22 Connect rl_reincarnation@localhost on rl_reincarnation 22 Query SET NAMES utf8 22 Query SHOW VARIABLES LIKE "%version%"
forward getsqldata();
forward OnPlayerDataLoaded(playerid);
public getsqldata()
{
mysql_log(LOG_ALL, LOG_TYPE_TEXT);
MySQL_Handle = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_BASE, MySQL_PASS, MySQL_PORT, true);
mysql_tquery(MySQL_Handle, "SHOW VARIABLES LIKE \"%version%\";", "OnPlayerDataLoaded", "d", 5);
print("call getsqldata");
}
public OnPlayerDataLoaded(playerid)
{
print("call OnPlayerDataLoaded");
return 1;
}
call getsqldata
0000: 4E 00 00 00 0A 35 2E 35 2E 33 32 2D 6C 6F 67 00 19 00 00 N....5.5.32-log.... 0013: 00 65 25 23 21 7B 6C 2D 38 00 FF F7 21 02 00 0F 80 15 00 .e%#!{l-8.ÿ÷!..... 0026: 00 00 00 00 00 00 00 00 00 70 4F 76 27 59 6C 34 5B 4E 55 .........pOv'Yl4[NU 0039: 43 2D 00 6D 79 73 71 6C 5F 6E 61 74 69 76 65 5F 70 61 73 C-.mysql_native_pas 004C: 73 77 6F 72 64 00 sword. 0000: 57 00 00 01 8D A2 06 00 00 00 00 40 08 00 00 00 00 00 00 W...¢.....@....... 0013: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 6C .................rl 0026: 5F 72 65 69 6E 63 61 72 6E 61 74 69 6F 6E 00 14 C8 96 3A _reincarnation..È: 0039: 15 82 2A E7 ED 65 EB BA B7 95 88 F5 06 6D 7C 62 C7 72 6C .*çíe뺷õ.m|bÇrl 004C: 5F 72 65 69 6E 63 61 72 6E 61 74 69 6F 6E 00 _reincarnation. 0000: 07 00 00 02 00 00 00 02 00 00 00 ........... 0000: 21 00 00 00 03 53 48 4F 57 20 56 41 52 49 41 42 4C 45 53 !....SHOW VARIABLES 0013: 20 4C 49 4B 45 20 22 25 76 65 72 73 69 6F 6E 25 22 3B LIKE "%version%"; 0000: 01 00 00 01 02 54 00 00 02 03 64 65 66 12 69 6E 66 6F 72 .....T....def.infor 0013: 6D 61 74 69 6F 6E 5F 73 63 68 65 6D 61 09 56 41 52 49 41 mation_schema.VARIA 0026: 42 4C 45 53 09 56 41 52 49 41 42 4C 45 53 0D 56 61 72 69 BLES.VARIABLES.Vari 0039: 61 62 6C 65 5F 6E 61 6D 65 0D 56 41 52 49 41 42 4C 45 5F able_name.VARIABLE_ 004C: 4E 41 4D 45 0C 21 00 C0 00 00 00 FD 01 00 00 00 00 4D 00 NAME.!.À...ý.....M. 005F: 00 03 03 64 65 66 12 69 6E 66 6F 72 6D 61 74 69 6F 6E 5F ...def.information_ 0072: 73 63 68 65 6D 61 09 56 41 52 49 41 42 4C 45 53 09 56 41 schema.VARIABLES.VA 0085: 52 49 41 42 4C 45 53 05 56 61 6C 75 65 0E 56 41 52 49 41 RIABLES.Value.VARIA 0098: 42 4C 45 5F 56 41 4C 55 45 0C 21 00 00 0C 00 00 FD 00 00 BLE_VALUE.!.....ý.. 00AB: 00 00 00 05 00 00 04 FE 00 00 22 00 16 00 00 05 0E 69 6E .......þ.."......in 00BE: 6E 6F 64 62 5F 76 65 72 73 69 6F 6E 06 35 2E 35 2E 33 32 nodb_version.5.5.32 00D1: 14 00 00 06 10 70 72 6F 74 6F 63 6F 6C 5F 76 65 72 73 69 .....protocol_versi 00E4: 6F 6E 02 31 30 18 00 00 07 16 73 6C 61 76 65 5F 74 79 70 on.10.....slave_typ 00F7: 65 5F 63 6F 6E 76 65 72 73 69 6F 6E 73 00 13 00 00 08 07 e_conversions...... 010A: 76 65 72 73 69 6F 6E 0A 35 2E 35 2E 33 32 2D 6C 6F 67 2D version.5.5.32-log- 011D: 00 00 09 0F 76 65 72 73 69 6F 6E 5F 63 6F 6D 6D 65 6E 74 ....version_comment 0130: 1C 4D 79 53 51 4C 20 43 6F 6D 6D 75 6E 69 74 79 20 53 65 .MySQL Community Se 0143: 72 76 65 72 20 28 47 50 4C 29 1C 00 00 0A 17 76 65 72 73 rver (GPL).....vers 0156: 69 6F 6E 5F 63 6F 6D 70 69 6C 65 5F 6D 61 63 68 69 6E 65 ion_compile_machine 0169: 03 78 38 36 19 00 00 0B 12 76 65 72 73 69 6F 6E 5F 63 6F .x86.....version_co 017C: 6D 70 69 6C 65 5F 6F 73 05 57 69 6E 33 32 05 00 00 0C FE mpile_os.Win32....þ 018F: 00 00 22 00 ..".
Логи плагина:
Код:
[17:29:24] [DEBUG] mysql_connect - host: "localhost", user: "rl_reincarnation", database: "rl_reincarnation", password: "****", port: 3306, autoreconnect: true, pool_size: 2 [17:29:24] [DEBUG] CMySQLHandle::Create - creating new connection.. [17:29:24] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called [17:29:24] [DEBUG] CMySQLHandle::Create - connection created (id: 1) [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] mysql_tquery - connection: 1, query: "SHOW VARIABLES LIKE "%version%";", callback: "OnPlayerDataLoaded", format: "d" [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLConnection::Connect - connection was successful [17:29:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [17:29:24] [DEBUG] CMySQLQuery::Execute[OnPlayerDataLoaded] - starting query execution [17:29:24] [DEBUG] CMySQLQuery::Execute[OnPlayerDataLoaded] - query was successfully executed within 0.651 milliseconds [17:29:24] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [17:29:24] [DEBUG] Calling callback "OnPlayerDataLoaded".. [17:29:24] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called Код:
141008 17:29:24 19 Connect rl_reincarnation@localhost on rl_reincarnation 19 Query SET NAMES utf8 20 Connect rl_reincarnation@localhost on rl_reincarnation 20 Query SET NAMES utf8 21 Connect rl_reincarnation@localhost on rl_reincarnation 21 Query SET NAMES utf8 22 Connect rl_reincarnation@localhost on rl_reincarnation 22 Query SET NAMES utf8 22 Query SHOW VARIABLES LIKE "%version%" PHP код:
Код:
call getsqldata Код:
0000: 4E 00 00 00 0A 35 2E 35 2E 33 32 2D 6C 6F 67 00 19 00 00 N....5.5.32-log.... 0013: 00 65 25 23 21 7B 6C 2D 38 00 FF F7 21 02 00 0F 80 15 00 .e%#!{l-8.ÿ÷!...€.. 0026: 00 00 00 00 00 00 00 00 00 70 4F 76 27 59 6C 34 5B 4E 55 .........pOv'Yl4[NU 0039: 43 2D 00 6D 79 73 71 6C 5F 6E 61 74 69 76 65 5F 70 61 73 C-.mysql_native_pas 004C: 73 77 6F 72 64 00 sword. 0000: 57 00 00 01 8D A2 06 00 00 00 00 40 08 00 00 00 00 00 00 W...¢.....@....... 0013: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 6C .................rl 0026: 5F 72 65 69 6E 63 61 72 6E 61 74 69 6F 6E 00 14 C8 96 3A _reincarnation..È–: 0039: 15 82 2A E7 ED 65 EB BA B7 95 88 F5 06 6D 7C 62 C7 72 6C .‚*çíe뺷•ˆõ.m|bÇrl 004C: 5F 72 65 69 6E 63 61 72 6E 61 74 69 6F 6E 00 _reincarnation. 0000: 07 00 00 02 00 00 00 02 00 00 00 ........... 0000: 21 00 00 00 03 53 48 4F 57 20 56 41 52 49 41 42 4C 45 53 !....SHOW VARIABLES 0013: 20 4C 49 4B 45 20 22 25 76 65 72 73 69 6F 6E 25 22 3B LIKE "%version%"; 0000: 01 00 00 01 02 54 00 00 02 03 64 65 66 12 69 6E 66 6F 72 .....T....def.infor 0013: 6D 61 74 69 6F 6E 5F 73 63 68 65 6D 61 09 56 41 52 49 41 mation_schema.VARIA 0026: 42 4C 45 53 09 56 41 52 49 41 42 4C 45 53 0D 56 61 72 69 BLES.VARIABLES.Vari 0039: 61 62 6C 65 5F 6E 61 6D 65 0D 56 41 52 49 41 42 4C 45 5F able_name.VARIABLE_ 004C: 4E 41 4D 45 0C 21 00 C0 00 00 00 FD 01 00 00 00 00 4D 00 NAME.!.À...ý.....M. 005F: 00 03 03 64 65 66 12 69 6E 66 6F 72 6D 61 74 69 6F 6E 5F ...def.information_ 0072: 73 63 68 65 6D 61 09 56 41 52 49 41 42 4C 45 53 09 56 41 schema.VARIABLES.VA 0085: 52 49 41 42 4C 45 53 05 56 61 6C 75 65 0E 56 41 52 49 41 RIABLES.Value.VARIA 0098: 42 4C 45 5F 56 41 4C 55 45 0C 21 00 00 0C 00 00 FD 00 00 BLE_VALUE.!.....ý.. 00AB: 00 00 00 05 00 00 04 FE 00 00 22 00 16 00 00 05 0E 69 6E .......þ.."......in 00BE: 6E 6F 64 62 5F 76 65 72 73 69 6F 6E 06 35 2E 35 2E 33 32 nodb_version.5.5.32 00D1: 14 00 00 06 10 70 72 6F 74 6F 63 6F 6C 5F 76 65 72 73 69 .....protocol_versi 00E4: 6F 6E 02 31 30 18 00 00 07 16 73 6C 61 76 65 5F 74 79 70 on.10.....slave_typ 00F7: 65 5F 63 6F 6E 76 65 72 73 69 6F 6E 73 00 13 00 00 08 07 e_conversions...... 010A: 76 65 72 73 69 6F 6E 0A 35 2E 35 2E 33 32 2D 6C 6F 67 2D version.5.5.32-log- 011D: 00 00 09 0F 76 65 72 73 69 6F 6E 5F 63 6F 6D 6D 65 6E 74 ....version_comment 0130: 1C 4D 79 53 51 4C 20 43 6F 6D 6D 75 6E 69 74 79 20 53 65 .MySQL Community Se 0143: 72 76 65 72 20 28 47 50 4C 29 1C 00 00 0A 17 76 65 72 73 rver (GPL).....vers 0156: 69 6F 6E 5F 63 6F 6D 70 69 6C 65 5F 6D 61 63 68 69 6E 65 ion_compile_machine 0169: 03 78 38 36 19 00 00 0B 12 76 65 72 73 69 6F 6E 5F 63 6F .x86.....version_co 017C: 6D 70 69 6C 65 5F 6F 73 05 57 69 6E 33 32 05 00 00 0C FE mpile_os.Win32....þ 018F: 00 00 22 00 ..". |