Something weird with dialog's inputtext
#1

pawn Код:
else if(dialogid == DIALOG_ADMINNAME)
    {
        if(response)
        {
            if(!strlen(inputtext))
            {
                format(string, sizeof(string), "Your existing Admin name is: %s\n\nPlease input a desired new one below.", PlayerData[playerid][AdminName]);
                ShowPlayerDialog(playerid, DIALOG_ADMINNAME, DIALOG_STYLE_INPUT, "Edit Administrator Name", string, "Enter", "Exit");
                return 1;
            }
            format(string, sizeof(string), "%s", strlen(inputtext));
            if(SetPlayerName(playerid, string))
            {
                strmid(PlayerData[playerid][AdminLevel], string, 0, strlen(string), 255);
                printf("%s - %s", PlayerData[playerid][AdminName], strlen(inputtext));
                format(string, sizeof(string), "Your new Admin name is: %s", PlayerData[playerid][AdminName]);
                ShowPlayerDialog(playerid, DIALOG_INFOx, DIALOG_STYLE_MSGBOX, "Information", string, "Okay", "");
                if(PlayerData[playerid][AdminDuty]) { SetPlayerName(playerid, PlayerData[playerid][AdminName]); }
            }
            else
            {
                format(string, sizeof(string), "That name you inputted wasn't a valid name.\nPlease make sure it does not contain special characters.", PlayerData[playerid][AdminName]);
                ShowPlayerDialog(playerid, DIALOG_ADMINNAME, DIALOG_STYLE_INPUT, "Edit Administrator Name", string, "Enter", "Exit");
                return 1;
            }
        }
        else
        {
            ShowPlayerDialog(playerid, DIALOG_ADMININFO, DIALOG_STYLE_LIST, "Admin Information", "Edit Admin Key\nEdit Admin Name\nDuty Status\nAuthorized Commands", "Select", "Cancel");
        }
   
        return 1;
    }
So I've got that dialog, and the inputtext is returning:
pawn Код:
dmin Name
No matter what I input, so if i input 'Jack' it will still return that.

Print result:
Код:
[10:28:07] dmin Name - dmin Name
(check the attachment to see the weird character it's inserting)

I've probably done some real noob mistake somewhere, but I can't notice anything wrong.
Reply
#2

format(string, sizeof(string), "%s", strlen(inputtext));
THIS is the problem line
%s is for strings
but sterlen returns integer type

change this line to the following
format(string, sizeof(string), "%s", inputtext);
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
change this line to the following
format(string, sizeof(string), "%s", inputtext);
im not sure but i think this will probably error..
Reply
#4

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
format(string, sizeof(string), "%s", strlen(inputtext));
THIS is the problem line
%s is for strings
but sterlen returns integer type

change this line to the following
format(string, sizeof(string), "%s", inputtext);
I always use "strlen(inputtext)" for cases like this, example:
pawn Код:
format(string, sizeof(string), "%s's response to your report:{FFFFFF} %s", GetPlayersName(playerid), strlen(inputtext));
SendClientMessage(target, COLOR_SERVER, string);
That works fine, how ever, in this case, I tried what you suggested, and just used "inputtext", and it worked fine. So thanks for that, still confused though lol.
Reply
#5

pawn Код:
else if(dialogid == DIALOG_ADMINNAME)
    {
        if(response)
        {
            if(!strlen(inputtext))
            {
                new fstr[90];
                format(fstr, sizeof(fstr), "Your existing Admin name is: %s\n\nPlease input a desired new one below.", PlayerData[playerid][AdminName]);
                return ShowPlayerDialog(playerid, DIALOG_ADMINNAME, DIALOG_STYLE_INPUT, "Edit Administrator Name", fstr, "Enter", "Exit");
            }
            new oldname[MAX_PLAYER_NAME];
            GetPlayerName(playerid, oldname, sizeof(oldname));
            if(SetPlayerName(playerid, inputtext))
            {
                SetPlayerName(playerid, oldname);
                format(oldname, sizeof(oldname), "%s", inputtext);
                PlayerData[playerid][AdminName] = oldname;
                printf("%s - %d", PlayerData[playerid][AdminName], strlen(inputtext));
                new fstr[50];
                format(fstr, sizeof(fstr), "Your new Admin name is: %s", PlayerData[playerid][AdminName]);
                ShowPlayerDialog(playerid, DIALOG_INFOx, DIALOG_STYLE_MSGBOX, "Information", fstr, "Okay", "");
                if(PlayerData[playerid][AdminDuty]) SetPlayerName(playerid, PlayerData[playerid][AdminName]);
            }
            else
            {
                SetPlayerName(playerid, oldname);
                return ShowPlayerDialog(playerid, DIALOG_ADMINNAME, DIALOG_STYLE_INPUT, "Edit Administrator Name", "That name you inputted wasn't a valid name.\nPlease make sure it does not contain special characters.", "Enter", "Exit");
            }
        }
        else ShowPlayerDialog(playerid, DIALOG_ADMININFO, DIALOG_STYLE_LIST, "Admin Information", "Edit Admin Key\nEdit Admin Name\nDuty Status\nAuthorized Commands", "Select", "Cancel");
        return 1;
    }
You were doing some weird stuff like:
pawn Код:
format(string, sizeof(string), "%s", strlen(inputtext));
if(SetPlayerName(playerid, string))
You know what 'strlen' is right?

--

I'm not sure if this is what you're trying to achieve, but hopefully I'm on the right track.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)