Numbers variable
#1

I have make an command /setnumber [111000-444000]
and i want player can only type an number between 11100 and 444000 , how i can check it? Thanks
Reply
#2

Hello.

Can you show us your command "/setnumber"?

- EDIT:
Normally you must use strval, but when I see your command I can say how you have to do this.
Reply
#3

Like this?
PHP код:
if(number 111000 || number 444000) return SendClientMessage(playerid, -1"Only between 111000 and 444000"); 
Reply
#4

PHP код:
cmd:setnumer(playeridparams[])
{
    new 
number;
    if(
sscanf(params"d"number)) return //wrong usage (didn't enter a number)
    
switch(number)
    {
        case 
111000..444000//code
        
default: //entered something else
    
}
    return 
1;

Reply
#5

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
cmd:setnumer(playeridparams[])
{
    new 
number;
    if(
sscanf(params"d"number)) return //wrong usage (didn't enter a number)
    
switch(number)
    {
        case 
111000..444000//code
        
default: //entered something else
    
}
    return 
1;

your switch will take so so so so so so so so so so so long time to get complied you had to simple use if statement.
PHP код:
CMD:setnumer(playeridparams[])
{
    new 
number;
    if(
sscanf(params"d"number)) return //wrong usage (didn't enter a number)
    
if(111000 >= number <= 444000)
    {
        
// number is between  111000  and  444000
    
}
    else
    {
        
// number isn't between 111000  and  444000
    
}
    return 
1;

Reply
#6

AFAIK switch is faster than if statements
Reply
#7

Quote:
Originally Posted by Shinja
Посмотреть сообщение
AFAIK switch is faster than if statements
You're totally wrong, switch and if are being used at totally different cases in switch case if is slower and in if case switch is slower.

You have to use the right one depend on what you wanna do.

for ex:
PHP код:
    switch(PlayerLeveL)
    {
        case 
1:
        case 
2:
        case 
3:
        case 
4:
        
//....
    
    

is faster than
PHP код:
    if(PlayerLeveL == 1)
    if(
PlayerLeveL == 2)
    if(
PlayerLeveL == 3)
    if(
PlayerLeveL == 4)
    
//... 
but at this case:

PHP код:
    if(>= PlayerLeveL <= 3500
if is faster than switch
PHP код:
switch(PlayerLeveL)
{
   case 
1..3500:

NOTE: why don't you test your code and show us how it will get complied?
Reply
#8

If you don't mind waiting MINUTES for your switch statement to compile, then use it.

Else, just stick with if statements. They get compiled in no time and the runtime speed loss over switch is insignifiant.
Reply
#9

Hey guys , thanks for replying me , i cant use my pc from friday , i will reply back when i will be able to use it ,maybe tommorw.
Thanks again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)