tonteria aparte... duda.
#1

buenas a todos, vengo a preguntarles una tonterнa pero no encuentro la soluciуn e no la veo el problema que lo causa.

el problema esta en que en el dialog se coloca solo el texto del ultimo array, y no deberнa.

PHP код:
new variable[][]={
{
"asd"},
{
"asd"},
{
"asd"},
{
"asd"},
// ...
};
new 
data[1000];
for(new 
index=0index<17index++){
    
format(data,sizeof(data),"%d. %s \n",index+1,variable[index]);
}
ShowPlayerDialog(playeridIDDIALOG_STYLE_TABLIST"titulo"data"seleccionar""cancelar"); 
desde ya muchas gracias.
Reply
#2

pawn Код:
new data[1000];
for(new index=0; index<17; index++)
    format(data,sizeof(data),"%s%d. %s \n", data,index+1,variable[index]);
Reply
#3

Por que estбs "seteando" el texto en el loop, usa strcat o como dijo M1tux3r tambiйn vale.
Reply
#4

Quote:
Originally Posted by adri1
Посмотреть сообщение
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.
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Es mejor hacer lo que M1tux3r dijo, ya que si utilizas strcat, tambien estarias usando format.
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);
Al usar el format en cada repeticion la funcion vuelve a sobrescribir los datos, mientras que con el strcat solo lo aсade al final haciendo que sea mбs rapida la ejecuciуn.
Reply
#6

Quote:
Originally Posted by Daniel-92
Посмотреть сообщение
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);
Al usar el format en cada repeticion la funcion vuelve a sobrescribir los datos, mientras que con el strcat solo lo aсade al final haciendo que sea mбs rapida la ejecuciуn.
Si, tienes razуn, es mas rбpido strcat + format que format solamente. Me dijo Konstantinos que era mejor, pero ya veo que no. Nunca hice las pruebas antes, pero ya, aquн estбn:



Reply
#7

Hay otra forma, aunque no se si serб mбs eficiente:

Код:
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);
Resultado:

Код:
0 1 2 3 4 5 6 7 8 9
Serнa cuestiуn de probarlo, pero de esta forma los datos sуlo se tienen que escribir una vez. De todas formas, hay que usar lo que mбs cуmodo le quede a cada uno ya que apenas se pierde tiempo re-escribiendo datos en la memoria.
Reply
#8

Vaya parece que ese es todavнa mas rбpido que el format + strcat, pero por poquito:











pawn Код:
// [ 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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)