Posts: 278
Threads: 100
Joined: May 2011
Reputation:
0
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
Posts: 1,311
Threads: 11
Joined: Mar 2015
Reputation:
0
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.
Posts: 1,266
Threads: 6
Joined: Oct 2014
Quote:
Originally Posted by Shinja
PHP код:
cmd:setnumer(playerid, params[])
{
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(playerid, params[])
{
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;
}
Posts: 969
Threads: 26
Joined: Jan 2016
Reputation:
0
AFAIK switch is faster than if statements
Posts: 1,266
Threads: 6
Joined: Oct 2014
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(1 >= 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?
Posts: 513
Threads: 4
Joined: Jun 2015
Reputation:
0
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.
Posts: 278
Threads: 100
Joined: May 2011
Reputation:
0
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