Help with dialog inputtext
#1

pawn Код:
if(dialogid == admin_security)
    {
        if(response)
        {
            if(strlen(inputtext))
            {
                if(inputtext == "anypasshere") // error line
                {
                    SCM(playerid,COLOR_SKYBLUE,"You Have Entered the correct admin password");
                    return 1;
                }
                else
                {
                    SCM(playerid,COLOR_RED,"You Have Entered the Wrong admin password");
                    ShowPlayerDialog(playerid,admin_security,DIALOG_STYLE_INPUT,"Admin Password",""SKYBLUE"Place The Admin Password Here","Admin Login","");
                }
            }
            else
            {
            ShowPlayerDialog(playerid,admin_security,DIALOG_STYLE_INPUT,"Admin Password",""SKYBLUE"Place The Admin Password Here","Admin Login","");
            SCM(playerid,COLOR_RED,"You Have Entered the Wrong admin password");
            }
        }
    }
error
pawn Код:
(7827) : error 033: array must be indexed (variable "inputtext")
Reply
#2

Inputtext is a string. You can't do a check like on the variable, to compare your inputtext to something use:

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

can u set it ??
Reply
#4

Can you read the link I have sent you?
Reply
#5

i read it but i don't know how to do it
Reply
#6

Okey, let me explain that to you like to 6 years old kid.

This is your error 033 line, isn't it? You have also found it:
pawn Код:
if(inputtext == "anypasshere")
Unfortunately, my dear boy you can't check STRING* like you're checking your variables. For example, when you check your normal variable, you're doing check (==) if your variable is the same as something else or some value.

* STRING is a pack of characters, like your message, text or anything else that contains characters. Read more about it in pawn.pdf or any other programming book.

In this case, my dear you have to use STRCMP which stands for STRING COMPARE. Simply, boy you have to use IF statement as you did, but instead of doing double equal sign you have to use strcmp function.

Syntax of STRCMP has been wonderfully described at WIKI page (the link I have sent before). Let's check on that then!



Wait! Doesn't it make sense now, and code just writing itself?
pawn Код:
if(strcmp(what is your first string???, what do you want to compare it to???))
Reply
#7

thanks bro now i got it all
Reply
#8

sorry but even i enter any other thing it works
Reply
#9

When the 2 strings are the same, it returns 0*. So:
pawn Код:
if (!strcmp(inputtext, "anypasshere"))
{
    // correct password
}
else
{
    // wrong password
}
* It also returns 0 when a string is null/emtpy so checking if the inputtext's lenght is not 0 would be useful.
Reply
#10

thanks and should i return an value on wrong pass too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)