new CommandExecuted[MAX_PLAYERS],
Variable2[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(CommandExecuted)
{
Variable2[playerid] = true;
}
else
{
Variable2[playerid] = false;
}
return 1;
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
Variable2[playerid] = (CommandExecuted) ? (true) : (false);
return 1;
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(Condicion == 1)
{
// SI SE CUMPLE EN 1
}
else if(Condicion == 2)
{
// SI SE CUMPLE EN 2
}
else
{
// SI NO SE CUMPLE NINGUNO
}
return 1;
}
return 0;
}
new bool:a, b = a ? 1 : 0;
printf("%d", b);
new data[100];
format(data,sizeof(data),"estado: %s",(GetPlayerSkin(playerid)==5) ? ("es gordo") : ("no es gordo"));
SendClientMessage(playerid,-1,data);
format(data,sizeof(data),"estado: %s",(GetPlayerState(playerid)==PLAYER_STATE_DRIVER) ? ("es conductor") : ("no es conductor"));
SendClientMessage(playerid,-1,data);
format(data,sizeof(data),"estado: %s",(GetPlayerWeapon(playerid)==30) ? ("tienes un AK-47") : ("no tienes un AK-47"));
SendClientMessage(playerid,-1,data);
new variable;
((variable == 1)?(true):(variable == 2)?(true):(variable == 3)?(true):(false));
[04:20:19] if: 2135
[04:20:20] ternary operator: 1696 [04:22:12] if: 2210 [04:22:14] ternary operator: 1726 [04:23:58] if: 2174 [04:24:00] ternary operator: 1689 Cуdigo: PHP Code:
|
new data[100]; format(data,sizeof(data),"estado: %s",(GetPlayerSkin(playerid)==5) ? ("es gordo") : ("no es gordo")); SendClientMessage(playerid,-1,data); format(data,sizeof(data),"estado: %s",(GetPlayerState(playerid)==PLAYER_STATE_DRIVER) ? ("es conductor") : ("no es conductor")); SendClientMessage(playerid,-1,data); format(data,sizeof(data),"estado: %s",(GetPlayerWeapon(playerid)==30) ? ("tienes un AK-47") : ("no tienes un AK-47")); SendClientMessage(playerid,-1,data);
buen tutorial, no hay muchos de esto y es una buena forma.
buen trabajo, saludos. aca otros ejemplo de uso ![]() Code:
new data[100]; format(data,sizeof(data),"estado: %s",(GetPlayerSkin(playerid)==5) ? ("es gordo") : ("no es gordo")); SendClientMessage(playerid,-1,data); format(data,sizeof(data),"estado: %s",(GetPlayerState(playerid)==PLAYER_STATE_DRIVER) ? ("es conductor") : ("no es conductor")); SendClientMessage(playerid,-1,data); format(data,sizeof(data),"estado: %s",(GetPlayerWeapon(playerid)==30) ? ("tienes un AK-47") : ("no tienes un AK-47")); SendClientMessage(playerid,-1,data); |
if(Condicion == 1) { // SI SE CUMPLE EN 1 } else if(Condicion == 2) { // SI SE CUMPLE EN 2 } else { // SI NO SE CUMPLE NINGUNO }
Esto
Code:
if(Condicion == 1) { // SI SE CUMPLE EN 1 } else if(Condicion == 2) { // SI SE CUMPLE EN 2 } else { // SI NO SE CUMPLE NINGUNO } |
switch(Condicion) { case 1:{} // SI SE CUMPLE EN 1 case 2:{} // SI SE CUMPLE EN 2 default:{} // NO SE CUMPLEN }
Si, y seria mas veloz.
Code:
switch(Condicion) { case 1:{} // SI SE CUMPLE EN 1 case 2:{} // SI SE CUMPLE EN 2 default:{} // NO SE CUMPLEN } |
new variable; ((variable == 1)?(true):(variable == 2)?(true):(variable == 3)?(true):(false));
No sй realmente si se compila y ejecuta mбs rбpidamente el ternario que el if, aunque creerнa que sн porque presta atenciуn sуlo a dos clбusulas pero en esto no podrнa asegurarles, espero haber sido de ayuda. |