dialog gender input
#1

how to get dialog_style_input's input and check if it's one of the genders

Код:
    if(dialogid == DIALOG_GENDER)
    {
        if(!response)
        {
            Kick(playerid);
        }
        else
        {
            if(strlen(inputtext))
            {
                new gender = inputtext;
                if(gender != "male" || gender != "female")
                {
                    ShowPlayerDialog(playerid, DIALOG_GENDER, DIALOG_STYLE_INPUT, "Gender","What is the gender of your character? (male/female)","Next","Quit");
                }
                else
                {
                    PlayerInfo[playerid][Gender] = gender;
                    new string[64];
                    format(string, sizeof(string), "You are %s", gender);
                    SendClientMessage(playerid, -1, string);
                }
            }
        }
    }
error 033: array must be indexed (variable "-unknown-")
error 001: expected token: "-string end-", but found "-identifier-"

Код:
                new gender = inputtext;
                if(gender != "male" || gender != "female")
Reply
#2

You can't compare strings like that. Use strcmp (cmp stands for compare)

pawn Код:
if(!strcmp(gender, "male") || !strcmp(gender, "female"))
// this means gender is equal to either male or female, remove the "!" to do the opposite
Reply
#3

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
You can't compare strings like that. Use strcmp (cmp stands for compare)

pawn Код:
if(!strcmp(gender, "male") || !strcmp(gender, "female"))
// this means gender is equal to either male or female, remove the "!" to do the opposite
thanks,

how do I get dialog's inputtext and put it under 'gender' variable?

Код:
 new gender = inputtext;
i get: error 033: array must be indexed (variable "-unknown-")
error 001: expected token: "-string end-", but found "-identifier-"
Reply
#4

Strings should be arrays so each character is stored in a cell. To get user's input use sscanf

Quote:
Originally Posted by v4yne1
Посмотреть сообщение
thanks,

how do I get dialog's inputtext and put it under 'gender' variable?

Код:
 new gender = inputtext;
i get: error 033: array must be indexed (variable "-unknown-")
error 001: expected token: "-string end-", but found "-identifier-"
pawn Код:
if(dialogid == DIALOG_GENDER)
{
    if(!response)
    {
        Kick(playerid);
    }
    else
    {
        if(strlen(inputtext))
        {
            new gender[8];
            if(sscanf(inputtext, "s[7]", gender))
                return 0; // The user's input is not a string, so it stops the code.

            if(strcmp(gender, "male") || strcmp(gender, "female")) // if the code doesn't stop, it will reach here and execute
            {
                ShowPlayerDialog(playerid, DIALOG_GENDER, DIALOG_STYLE_INPUT, "Gender","What is the gender of your character? (male/female)","Next","Quit");
            }
            else
            {
                strcat(PlayerInfo[playerid][Gender], gender, 8); // Dont copy strings directly, use strcat.
                new string[16];
                format(string, sizeof(string), "You are %s", gender);
                SendClientMessage(playerid, -1, string);
            }
        }
    }
}
Reply
#5

now when I type anything it puts it as my gender

for example

i type 'a' it sends me a message my gender is 'a'

id like to make male and female only valid answers(genders)
Reply
#6

Quote:
Originally Posted by v4yne1
Посмотреть сообщение
now when I type anything it puts it as my gender

for example

i type 'a' it sends me a message my gender is 'a'

id like to make male and female only valid answers(genders)
Try again, I updated the code.
Reply
#7

doesn't work.

nothing works, only when i leave it blank and press enter. then the dialog just closes. but other answers dont work at all. the dialog just shows over an over
Reply
#8

You can also do the dialog as a select list instead of input.

pawn Код:
ShowPlayerDialog(playerid, GENDER_DIALOG_ID, DIALOG_STYLE_LIST, "Select your gender", "Male\nFemale", "Select", "Close");

//OnDialogReponse
switch(dialogid)
{
    case GENDER_DIALOG_ID:
    {
        if(response)
        {
            switch(listitem)
            {
                case 0: PlayerInfo[playerid][Gender] = 1; //player is a male
                case 1: PlayerInfo[playerid][Gender] = 2; //player is a female
            }
        }
    }
}
Reply
#9

Quote:
Originally Posted by ConnorW
Посмотреть сообщение
You can also do the dialog as a select list instead of input.

pawn Код:
ShowPlayerDialog(playerid, GENDER_DIALOG_ID, DIALOG_STYLE_LIST, "Select your gender", "Male\nFemale", "Select", "Close");

//OnDialogReponse
switch(dialogid)
{
    case GENDER_DIALOG_ID:
    {
        if(response)
        {
            switch(listitem)
            {
                case 0: PlayerInfo[playerid][Gender] = 1; //player is a male
                case 1: PlayerInfo[playerid][Gender] = 2; //player is a female
            }
        }
    }
}
yeah, i know that.

but i want to do it with an input dialog
Reply
#10

Quote:
Originally Posted by v4yne1
Посмотреть сообщение
yeah, i know that.

but i want to do it with an input dialog
Here
pawn Код:
if(dialogid == DIALOG_GENDER)
    {
        if(!response)
        {
            Kick(playerid);
        }
        else
        {
            if(response)
            {
                if (!strcmp(inputtext, "male"))
                {
                    PlayerInfo[playerid][Gender] = 1; // male
                    SendClientMessage(playerid, -1, "You are a male");
                }
                else if (!strcmp(inputtext, "female"))
                {
                    PlayerInfo[playerid][Gender] = 2;
                    SendClientMessage(playerid, -1, "You are a female");
                }
                else {
                    return ShowPlayerDialog(playerid, DIALOG_GENDER, DIALOG_STYLE_INPUT, "Gender","What is the gender of your character? (male/female)","Next","Quit");
                }
            }
        }
    }
Reply
#11

Quote:
Originally Posted by ConnorW
Посмотреть сообщение
Here
pawn Код:
if(dialogid == DIALOG_GENDER)
    {
        if(!response)
        {
            Kick(playerid);
        }
        else
        {
            if(response)
            {
                if (!strcmp(inputtext, "male"))
                {
                    PlayerInfo[playerid][Gender] = 1; // male
                    SendClientMessage(playerid, -1, "You are a male");
                }
                else if (!strcmp(inputtext, "female"))
                {
                    PlayerInfo[playerid][Gender] = 2;
                    SendClientMessage(playerid, -1, "You are a female");
                }
                else {
                    return ShowPlayerDialog(playerid, DIALOG_GENDER, DIALOG_STYLE_INPUT, "Gender","What is the gender of your character? (male/female)","Next","Quit");
                }
            }
        }
    }
thanks <3

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
Excuse me, but what's the point of using an input dialog? I still can write "my gender is not your business" and it'll be saved. I can't see the sense. Just make a dialog list. Avoid any further trolling from players.
its just matter of ideas and learning. from this example i can see how to use it in future and etc.

ty guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)