Evaluating Inputtext -
TKZ227 - 27.05.2013
I always get confused when working with inputtext.
How would I check if the inputtext of a dialog is a valid name or ID?
Re: Evaluating Inputtext -
Pupak - 27.05.2013
You can use
sscanf for that. Example:
Код:
new player;
if(!sscanf(inputtext, "u", player))
{
// Input text is valid player name / ID
}
Re: Evaluating Inputtext -
TKZ227 - 28.05.2013
When I type nothing into the dialog, your code works. If I type in something like "fsfsfs" (which obviously is not a valid player name), it doesn't work.
I need it to check if the text entered into the input box is a valid name or ID.
Re: Evaluating Inputtext -
Hoborific - 28.05.2013
OnDialogResponse handles a parameter "response" so if(Dialogid == whatever && response) will deal with empty strings being returned.
Re: Evaluating Inputtext -
CmZxC - 28.05.2013
add before sscanf line
pawn Код:
if(!strlen(inputtext))
{
// what do you want to do now, when there is nothing written in it
}
Re: Evaluating Inputtext -
CJay9209 - 28.05.2013
or save urself the time to use strlen and simply do:
pawn Код:
if(!response) {
//do what u need to for a blank string here
return 1;
}
//do what you want here if the string is not blank
return 1;
using strlen is a completely redundant and useless statement under ondialogresponse as it already takes it into account
(and I'm pretty sure that was mentioned before...)
Re: Evaluating Inputtext -
Pupak - 28.05.2013
Imagine this situation - player types nothing in the input box but still responses to the dialog.
OnDialogResponse gets called, parameter
response is positive and there is no input text.
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response && strlen(inputtext))
{
new player;
if(!sscanf(inputtext, "u", player))
{
// Input text is valid player name / ID
}
else
{
// Input text is NOT valid player name / ID
}
}
}
Please note that I don't have San Andreas and haven't tested this, so using
strlen could be redudant if response is negative when there is no input text.
Re: Evaluating Inputtext -
Vince - 28.05.2013
That's not how sscanf works. Its return value is a value indicating if the amount of supplied parameters is correct. You need an additional check to see if the player is connected.
pawn Код:
if(!sscanf(inputtext, "u", player))
{
if(player != INVALID_PLAYER_ID)
{
// code here
}
}
Re: Evaluating Inputtext -
CJay9209 - 28.05.2013
yes but that don't check if the string is completely blank. I hit that problem earlier this week where you pass an empty string at ondialogresponse and it crashes your server...
as i said if response is 1 then its valid. if it's 0 then it's not - you DO NOT NEED TO USE STRLEN lol.
Also that scanf line only checks for valid player id or name - not if the string is blank. If you wanted to check a blank stirng then i'd actually just use isnull(inputtext) as it's a hell of alot faster.