Array - 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: Array (
/showthread.php?tid=624609)
Array -
GoldenLion - 19.12.2016
Hi, Is it possible to check if an array contains a certain number without looping through the elements?
Re: Array -
SickAttack - 19.12.2016
No. Why though? Loops are fast enough.
Use break; once you find the number.
Re: Array -
GoldenLion - 19.12.2016
Quote:
Originally Posted by SickAttack
No. Why though? Loops are fast enough.
Use break; once you find the number.
|
Well I was just wondering. Thanks.
Re: Array -
SickAttack - 19.12.2016
It is possible if you put each number in their index however.
if(array[number] == number]) or even as a boolean.
Re: Array -
SyS - 19.12.2016
I think container data types like vector is possible by using this plugin.
https://sampforum.blast.hk/showthread.php?tid=238844
Re: Array -
SickAttack - 19.12.2016
Quote:
Originally Posted by Sreyas
|
Comments say it is slower than normal arrays and work like PVars, so I don't see the point of why you should avoid a simple loop.
Re: Array -
SyS - 19.12.2016
Quote:
Originally Posted by SickAttack
Comments say it is slower than normal arrays and work like PVars, so I don't see the point of why you should avoid a simple loop.
|
The OP just want to know if its possible not that he is going to implement it. There is no harm in asking.
Re: Array -
SickAttack - 19.12.2016
Quote:
Originally Posted by Sreyas
The OP just want to know if its possible not that he is going to implement it. There is no harm in asking.
|
Then you should have posted something in pawn.
Re: Array -
SyS - 19.12.2016
Quote:
Originally Posted by SickAttack
Then you should have posted something in pawn.
|
Huh

I believe that plugin allows users to implement vectors in pawn.
Re: Array -
SyS - 18.03.2017
Sorry for late reply but i found something. Its actually possible. Since pawn is type less we can make use string function strfind to check it . I made a small macro for convenience. Its actually faster than normal looping.But there is a disadvantage if we have an element value equal to 0 the checking stops on that index and further index would not be checked and will return -1.I will try to find a method to overcome this.
PHP код:
#define arrfind(%0,%1) strfind(%0,{%1},false,0)
main()
{
new array[]={6,2,3,3,2340,78};
printf( "index = %d" , arrfind(array,3));//will print 2
}
now there is another way for checking without looping which is recursion but i think normal looping is better than that.