Numbers variable - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Numbers variable (
/showthread.php?tid=617199)
Numbers variable -
jimis - 17.09.2016
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
Re: Numbers variable -
Mencent - 17.09.2016
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.
Re: Numbers variable -
Dayrion - 17.09.2016
Like this?
PHP код:
if(number < 111000 || number > 444000) return SendClientMessage(playerid, -1, "Only between 111000 and 444000");
Re: Numbers variable -
Shinja - 17.09.2016
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;
}
Re: Numbers variable -
jlalt - 17.09.2016
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;
}
Re: Numbers variable -
Shinja - 17.09.2016
AFAIK switch is faster than if statements
Re: Numbers variable -
jlalt - 17.09.2016
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?
Re: Numbers variable -
Spmn - 17.09.2016
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.
Re: Numbers variable -
jimis - 19.09.2016
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