Checking if inputtext is 4 digits.
#1

Evening,

I want to check if the pincode an administrator selected is 4 digits long.

I tried to do that this way.

PHP код:
        if(sscanf(params"d"pass)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /changeadminpin [Pin code]");
        if(
strlen(pass) < || strlen(pass) > 4) return SendClientMessage(playeridCOLOR_WHITE"SERVER: The pincode must be 4 digits."); 
But this is not working, if I try to compile it is showing me these errors.
Код:
C:\Users\fabio\Desktop\International Roleplay\gamemodes\I-RP.pwn(2306) : error 035: argument type mismatch (argument 1)
C:\Users\fabio\Desktop\International Roleplay\gamemodes\I-RP.pwn(2328) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Reply
#2

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

I want to check if the pincode an administrator selected is 4 digits long.

I tried to do that this way.

PHP код:
        if(sscanf(params"d"pass)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /changeadminpin [Pin code]");
        if(
strlen(pass) < || strlen(pass) > 4) return SendClientMessage(playeridCOLOR_WHITE"SERVER: The pincode must be 4 digits."); 
But this is not working, if I try to compile it is showing me these errors.
Код:
C:\Users\fabio\Desktop\International Roleplay\gamemodes\I-RP.pwn(2306) : error 035: argument type mismatch (argument 1)
C:\Users\fabio\Desktop\International Roleplay\gamemodes\I-RP.pwn(2328) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
You are not declaring pass as a string. In order to use strlen 'pass" should be a string.
Reply
#3

There are better ways, but rearranging your code will do fine:
pawn Код:
if(strlen(params) != 4) return SendClientMessage(playerid, COLOR_WHITE, "SERVER: The pincode must be 4 digits.");
        if(sscanf(params, "d", pass)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /changeadminpin [Pin code]");
Reply
#4

Solved.
Reply
#5

Weird, It works perfect now but if I set someone else or mine admin pin to "0000" the "SendClientMessage" displays "0". How to solve this?

Nevermind, solved it.
Reply
#6

Another problem popped up, this is the code now:
PHP код:
CMD:changeadminpin(playeridparams[])
{
    new 
pass[4], string[128];
    if(
PlayerInfo[playerid][pAdmin] >= 1)
    {
        if(
sscanf(params"s[4]"pass)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /changeadminpin [Pin code]");
        if(
strlen(pass) != 4) return SendClientMessage(playeridCOLOR_WHITE"SERVER: The pincode must be 4 digits.");
        
sscanf(pass"i"PlayerInfo[playerid][pSecKey]);
         
format(stringsizeof(string), "{FFFFFF}SERVER: You've successfully changed your pin code to %s."pass);
         
SendClientMessage(playeridCOLOR_WHITEstring);
    }
    else return 
SendClientMessage(playeridCOLOR_GRAD2NOTADMIN);
    return 
1;

But even if I only type in 4 digits. it still gives the "SERVER:" message, and doesn't set the pin.
Reply
#7

Make sure to save the pin as a string because numbers that start with a zero will bug out.. like "0000" or "0123"..

It should be:
PHP код:
strcpy(passPlayerInfo[playerid][pSecKey]); 
instead of sscanf.. for strings.

And don't forget to change all instances of integer to a 4 digit string.
Reply
#8

Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
Make sure to save the pin as a string because numbers that start with a zero will bug out.. like "0000" or "0123"..

It should be:
PHP код:
strcpy(passPlayerInfo[playerid][pSecKey]); 
instead of sscanf.. for strings.

And don't forget to change all instances of integer to a 4 digit string.
Not what I asked for, check my last message.
Reply
#9

Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
Make sure to save the pin as a string because numbers that start with a zero will bug out.. like "0000" or "0123"..

It should be:
PHP код:
strcpy(passPlayerInfo[playerid][pSecKey]); 
instead of sscanf.. for strings.

And don't forget to change all instances of integer to a 4 digit string.
False, it will not bug out. If you want to print the leading zero's you can easily do so.

Quote:
Originally Posted by faff
Посмотреть сообщение
Not what I asked for, check my last message.
You shouldn't use two sscanf strings for that. If you'd do it like I said it would be better. It's your code however, do as you will.

Now about the leading zero's. You shouldn't store it as a string to get them. You said:
Quote:

Weird, It works perfect now but if I set someone else or mine admin pin to "0000" the "SendClientMessage" displays "0". How to solve this?

The correct way to do this would be this (example):
pawn Код:
printf("This number will have three leading zeros: %4i", 0);
//Output: "This number will have three leading zeros: 0000"

printf("These numbers will all be four digits, with leading zeros if needed: %4i, %4i, %4i", 12, 555, 045);
//Output: "These numbers will all be four digits, with leading zeros if needed: 0012, 0555, 0045"
Reply
#10

Quote:
Originally Posted by Crayder
Посмотреть сообщение
False, it will not bug out. If you want to print the leading zero's you can easily do so.



You shouldn't use two sscanf strings for that. If you'd do it like I said it would be better. It's your code however, do as you will.

Now about the leading zero's. You shouldn't store it as a string to get them. You said:The correct way to do this would be this (example):
pawn Код:
printf("This number will have three leading zeros: %4i", 0);
//Output: "This number will have three leading zeros: 0000"

printf("These numbers will all be four digits, with leading zeros if needed: %4i, %4i, %4i", 12, 555, 045);
//Output: "These numbers will all be four digits, with leading zeros if needed: 0012, 0555, 0045"
Oh.. That's something new to me tbh.. :P
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)