new variable[][]={
{"asd"},
{"asd"},
{"asd"},
{"asd"},
// ...
};
new data[1000];
for(new index=0; index<17; index++){
format(data,sizeof(data),"%d. %s \n",index+1,variable[index]);
}
ShowPlayerDialog(playerid, ID, DIALOG_STYLE_TABLIST, "titulo", data, "seleccionar", "cancelar");
new data[1000];
for(new index=0; index<17; index++)
format(data,sizeof(data),"%s%d. %s \n", data,index+1,variable[index]);
|
Por que estбs "seteando" el texto en el loop, usa strcat o como dijo M1tux3r tambiйn vale.
|
|
Es mejor hacer lo que M1tux3r dijo, ya que si utilizas strcat, tambien estarias usando format.
|
format(string,sizeof(string),"%d. %s \n",index+1,variable[index]); strcat(data,string);
|
Por cuestiones de rendimiento es mucho mejor usar strcat, se ve mejor y solo ocupas una linea de mas.
Код:
format(string,sizeof(string),"%d. %s \n",index+1,variable[index]); strcat(data,string); |

new string[256];
new length = 0;
for(new i = 0; i < 10; i++)
{
format(string[length], 256 - length, "%d ", i);
length = strlen(string);
}
printf(string);
0 1 2 3 4 5 6 7 8 9





// [ DEVELOPMENT GAMEMODE ]
// INCLUDES:
#include <a_samp>
// RULES:
#pragma dynamic 1000000
// DEFINES:
#define MAX_ITERATIONS 10000
// MAIN:
main()
{
print("Development Mode: format_benchmark.amx");
new string_1[10000], temp[128], tick_1[2];
tick_1[0] = GetTickCount();
for(new i = 0; i < MAX_ITERATIONS; i ++)
{
format(temp, sizeof(temp), "%d", i);
strcat(string_1, temp);
}
tick_1[1] = GetTickCount();
new string_2[10000], tick_2[2];
tick_2[0] = GetTickCount();
for(new i = 0; i < MAX_ITERATIONS; i ++)
{
format(string_2, sizeof(string_2), "%s%d", string_2, i);
}
tick_2[1] = GetTickCount();
new string_3[10000], tick_3[2], lenght;
tick_3[0] = GetTickCount();
for(new i = 0; i < MAX_ITERATIONS; i ++)
{
format(string_3[lenght], 10000 - lenght, "%d", i);
lenght = strlen(string_3);
}
tick_3[1] = GetTickCount();
printf("format and strcat: %d", tick_1[1] - tick_1[0]);
printf("format: %d", tick_2[1] - tick_2[0]);
printf("format-lenght: %d", tick_3[1] - tick_3[0]);
}
// CALLBACKS:
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}