SA-MP Forums Archive
Consulta sobre dialog y variables. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Español/Spanish (https://sampforum.blast.hk/forumdisplay.php?fid=29)
+---- Thread: Consulta sobre dialog y variables. (/showthread.php?tid=523376)



Consulta sobre dialog y variables. - YazukiAkira - 01.07.2014

Tengo una duda con esto, їcomo puedo ir guardando valores enteros y de tipo string del dialog para luego recuperarlos en una funcion?

EJ:

pawn Код:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Ingrese su clave", "Su clave debe contener letras y numeros.", "Siguiente", "");

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            // їAqui deberia guardar la clave en una variable de tipo string?
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Ingrese su edad", "Pulsa siguiente.", "Siguiente", "");
        }
    }
    if(dialogid == 2)
    {
        if(response)
        {
            // їAqui deberia guardar la edad en una variable de tipo entero?
            ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Seleccione su genero", "Hombre\nMujer.", "Siguiente", "");
        }
    }
    if(dialogid == 3)
    {
        switch (listitem)
        {
            case 0:
            {
                // Es hombre
                // їAqui deberia guardar la edad en una variable de tipo entero?
                // Ejecuto una funcion
                GuardarDatos(playerid);
            }
            case 1:
            {
                // Es mujer
                // їAqui deberia guardar la edad en una variable de tipo entero?
                // Ejecuto una funcion
                GuardarDatos(playerid);
            }
        }
    }
    return 1;
}

stock GuardarDatos(playerid)
{
    // Aqui quiero recuperar los datos almacenados en las variables, luego pienso hacer un INSERT a una tabla de MYSQL con los datos de las variables
    // їComo podria hacer eso?
}
Agradezco algun ejemplo con SetPVar* y GetPVar* en int y string, tambiйn con Enum.

Gracias


Respuesta: Consulta sobre dialog y variables. - Kemula - 01.07.2014

Quote:
Originally Posted by YazukiAkira
Посмотреть сообщение
Tengo una duda con esto, їcomo puedo ir guardando valores enteros y de tipo string del dialog para luego recuperarlos en una funcion?

EJ:

pawn Код:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Ingrese su clave", "Su clave debe contener letras y numeros.", "Siguiente", "");

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            // їAqui deberia guardar la clave en una variable de tipo string?
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Ingrese su edad", "Pulsa siguiente.", "Siguiente", "");
        }
    }
    if(dialogid == 2)
    {
        if(response)
        {
            // їAqui deberia guardar la edad en una variable de tipo entero?
            ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Seleccione su genero", "Hombre\nMujer.", "Siguiente", "");
        }
    }
    if(dialogid == 3)
    {
        switch (listitem)
        {
            case 0:
            {
                // Es hombre
                // їAqui deberia guardar la edad en una variable de tipo entero?
                // Ejecuto una funcion
                GuardarDatos(playerid);
            }
            case 1:
            {
                // Es mujer
                // їAqui deberia guardar la edad en una variable de tipo entero?
                // Ejecuto una funcion
                GuardarDatos(playerid);
            }
        }
    }
    return 1;
}

stock GuardarDatos(playerid)
{
    // Aqui quiero recuperar los datos almacenados en las variables, luego pienso hacer un INSERT a una tabla de MYSQL con los datos de las variables
    // їComo podria hacer eso?
}
Agradezco algun ejemplo con SetPVar* y GetPVar* en int y string, tambiйn con Enum.

Gracias
pawn Код:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Ingrese su clave", "Su clave debe contener letras y numeros.", "Siguiente", "");

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            SetPVarString(playerid, "Clave", inputtext); //la almacenamos en Clave
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Ingrese su edad", "Pulsa siguiente.", "Siguiente", "");
        }
    }
    if(dialogid == 2)
    {
        if(response)
        {
            SetPVarInt(playerid, "Edad", inputtext);// Se almacena la edad
            ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Seleccione su genero", "Hombre\nMujer.", "Siguiente", "");
        }
    }
    if(dialogid == 3)
    {
        switch (listitem)
        {
            case 0:
            {
                                SetPVarInt(playerid, "Genero", 0); //Nombramos a la variable Genero, y le damos el valor 0, equivalente a hombre
                GuardarDatos(playerid);
            }
            case 1:
            {
                                SetPVarInt(playerid, "Genero", 1); //Nombramos a la variable de la misma forma, y le damos valor 1, equivalente a mujer
                GuardarDatos(playerid);
            }
        }
    }
    return 1;
}

stock GuardarDatos(playerid)
{
new clave[25]; //si consideramos que la contraseсa no va a contener mбs de 24 caracteres
           //guardarlos a MySQL
}
Para obtener el valor de la variable, se usarнa:
pawn Код:
GetPVarString(playerid, "Clave", clave, 25); //cogemos el valor de la variable Clave y lo llevamos a la otra, para procesarlo posteriormente.
/* GetPVarString(playerid, "Nombrevariable", variableguardado, longitudvariableguardado); */
GetPVarInt(playerid, "Edad");
GetPVarInt(playerid, "Genero");
Creo que seria asi, no sй si me he confundido en algo o no.


Respuesta: Consulta sobre dialog y variables. - YazukiAkira - 02.07.2014

Otra consulta, una vez almacenada la variable con SetPVar* esta estaria disponible en todo momento que el jugador este conectado para trabajar con sus datos? Que diferencia tendria esto a trabajar con Enum, el fin seria el mismo guardar datos en variables.

їQue me aconsejan y porque?

Gracias por la ayuda brindada.


Respuesta: Consulta sobre dialog y variables. - Kemula - 02.07.2014

Si, se almacenan durante todo el tiempo que el jugador estй online. Pero mi consejo, es que uses Enum.

Un saludo.