AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ArrayFindString Issue (https://forums.alliedmods.net/showthread.php?t=335556)

ConorCC 12-13-2021 17:26

ArrayFindString Issue
 
Hey There!

I just realized ArrayFindString will returns the index of the first occurence of the specified string. As it says in the documentation.

If you have an array like:
- de_dust2_long
- de_nuke

And you are looking for a string like:
- de_dust2

The function will returns 0 instead of -1. I know de_dust2 is part of de_dust2_long, but wouldn't be nice a 3rd param of the original function to search exact string or substing?

PHP Code:

ArrayFindStringEx(&Array: WhichszItem[], bExact 1) {

    if ( !
bExact )
        return 
ArrayFindString(WhichszItem);

    new 
szTmpItem[32], iArraySize ArraySize(Which);

    for ( new 
iiArraySize++ ) {

        
ArrayGetString(WhichiszTmpItemcharsmax(szTmpItem));

        if ( 
equal(szItemszTmpItem) )
            return 
i;
    }

    return -
1;



fysiks 12-13-2021 22:05

Re: ArrayFindString Issue
 
This has been reported here but in the context of this being a bug of the original function. I personally agree with this being a bug for this function as opposed to a feature request to be added.

Shadows Adi 12-14-2021 08:29

Re: ArrayFindString Issue
 
Check this out, it does the same thing but it compares every item from array.
https://forums.alliedmods.net/showth...=329651&page=2

HamletEagle 12-14-2021 10:12

Re: ArrayFindString Issue
 
Quote:

Originally Posted by fysiks (Post 2765940)
This has been reported here but in the context of this being a bug of the original function. I personally agree with this being a bug for this function as opposed to a feature request to be added.

I don't know if I would call it a bug, but it certainly is not intuitive. In the example provided by op, I would expect to get -1, not 0.
At this point, the functionality can not be changed(to keep backwards compatibility), but a new argument shoule be added to control how the string is matched.

fysiks 12-14-2021 20:27

Re: ArrayFindString Issue
 
Quote:

Originally Posted by HamletEagle (Post 2765987)
At this point, the functionality can not be changed(to keep backwards compatibility)

I certainly understand the argument but you could also argue that 1.9.0 has never actually been "released" and therefore people cant necessarily expect things not to change :wink:.

CrazY. 12-18-2021 08:19

Re: ArrayFindString Issue
 
And should include another argument for case sensitiveness. In its current state, there is no real use, you'd better just write a stock for searching strings.


All times are GMT -4. The time now is 11:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.